Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 1d0318e

Browse files
author
Michael Grauer
committed
BUG: refs #0458. Changed check to search for first existing parent dir.
1 parent 548f254 commit 1d0318e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

core/controllers/components/HttpuploadComponent.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,37 @@ public function generateToken($args, $dirname = '')
7474

7575
if(!file_exists($dir))
7676
{
77-
if(!is_writable($dir) || !mkdir($dir, 0700, true))
77+
78+
// this bit of logic will detect permissions problems, and prevent the
79+
// json encoding from breaking, when mkdir attempts to create a dir that
80+
// it doesn't have permissions for.
81+
//
82+
// search backwards up towards the root, look for the first existing dir
83+
$correctPermissions = false;
84+
// back up one directory to the current dir's root
85+
$dirRoot = dirname($dir);
86+
while(!$correctPermissions)
87+
{
88+
if(file_exists($dirRoot))
89+
{
90+
if(!is_writeable($dirRoot))
91+
{
92+
// if the closest existing root dir isn't writable that is an error
93+
throw new Exception('Failed to create temporary upload dir because a parent dir is not writeable', MIDAS_HTTPUPLOAD_TMP_DIR_CREATION_FAILED);
94+
}
95+
else
96+
{
97+
$correctPermissions = true;
98+
}
99+
}
100+
else
101+
{
102+
// back up one directory to the current dirRoot's root
103+
$dirRoot = dirname($dir);
104+
}
105+
}
106+
107+
if(!mkdir($dir, 0700, true))
78108
{
79109
throw new Exception('Failed to create temporary upload dir', MIDAS_HTTPUPLOAD_TMP_DIR_CREATION_FAILED);
80110
}

0 commit comments

Comments
 (0)