PHP mkdir() does not set file permissions as expected when we create directories recursively (See http://us.php.net/manual/en/function.mkdir.php#100106 for more information.) As a result:
- file_prepare_directory does not set the permissions to folders it has created recursively
- Users on shared hosting cannot delete the directories created by image module. ( )
The original patches addressed the issue at the drupal_mkdir() level, but it must also be addressed at the LocalStreamWrapper level. Also we do not want to repeat the code for the recursive bits in both locations, so the best way to address it is with a new function drupal_mkdir_local() to also recursively set the permissions.
Here's the IRC discussion. Let's presume you have an URI like s3://styles/large/s3/foo.jpg (coming from image_style_path). This does not mean that s3://styles/large has any meaning at all. Core does not use it, so why should the stream wrapper handle it? Accessing it might throw an exception for all you know. (see also http://www.advomatic.com/blogs/aaron-winborn/stream-wrappers-and-you ). So what we need to do is:
- Introduce drupal_mkdir_local().This handles file paths like sites/default/files/styles/large/public/foo.jpg and NOT schemed URIs. Can be refactored from http://drupalbin.com/21585
- drupal_mkdir checks for a scheme, if it's not there, it's a local path so it calls drupal_mkdir_local(). http://privatepaste.com/fda114cd01
- The local stream wrapper already has a local path so it calls drupal_mkdir_local(). http://privatepaste.com/7a5832a7fd
- Write a simpletest to check a new recursively created local directory for correct file system permissions.
- Backport the above to D7 s#DrupalLocalStreamWrapper::mkdir#LocalStreamWrapper::mkdir#
Original report by [weboide]
// Text of original report here.
file_prepare_directory does not seem to set the permissions to folders it has created recursively.
$conf['file_chmod_directory'] = 02775; // even tried with 0775
And then run:
$f = 'public://test1/test2/test3/'; file_prepare_directory(\$f, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
`-- [drwxr-sr-x] test1 `-- [drwxr-sr-x] test2 `-- [drwxrwxr-x] test3
I was expecting to see test1 and test2 with group write permission.
PASSED: [[SimpleTest]]: [MySQL] 41,614 pass(es). View
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 113,550 pass(es). View
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Unable to apply patch 1068266-mkdir_recursive-96.patch. Unable to apply patch. See the log in the details link for more information. View