Issue #2043771 by jbrown, joachim: Fixed drupal_mkdir() can't create an absolute path recursively.

8.0.x
Alex Pott 2013-07-30 21:01:09 +02:00
parent dc93cfdcb1
commit 420f38c5b8
2 changed files with 17 additions and 1 deletions

View File

@ -1475,8 +1475,19 @@ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {
$uri = str_replace('/', DIRECTORY_SEPARATOR, $uri);
// Determine the components of the path.
$components = explode(DIRECTORY_SEPARATOR, $uri);
// If the filepath is absolute the first component will be empty as there
// will be nothing before the first slash.
if ($components[0] == '') {
$recursive_path = DIRECTORY_SEPARATOR;
// Get rid of the empty first component.
array_shift($components);
}
else {
$recursive_path = '';
}
// Don't handle the top-level directory in this loop.
array_pop($components);
$recursive_path = '';
// Create each component if necessary.
foreach ($components as $component) {
$recursive_path .= $component;

View File

@ -50,6 +50,11 @@ class DirectoryTest extends FileTestBase {
// Check that existing directory permissions were not modified.
$this->assertDirectoryPermissions($directory, $old_mode);
// Check creating a directory using an absolute path.
$absolute_path = drupal_realpath($directory) . DIRECTORY_SEPARATOR . $this->randomName() . DIRECTORY_SEPARATOR . $this->randomName();
$this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File');
$this->assertDirectoryPermissions($absolute_path, 0775);
}
/**