This repository was archived by the owner on Sep 10, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
core/controllers/components Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,37 @@ public function generateToken($args, $dirname = '')
74
74
75
75
if (!file_exists ($ dir ))
76
76
{
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 ))
78
108
{
79
109
throw new Exception ('Failed to create temporary upload dir ' , MIDAS_HTTPUPLOAD_TMP_DIR_CREATION_FAILED );
80
110
}
You can’t perform that action at this time.
0 commit comments