Commit 420f38c5 authored by alexpott's avatar alexpott

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

parent dc93cfdc
......@@ -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;
......
......@@ -50,6 +50,11 @@ function testFileCheckLocalDirectoryHandling() {
// 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);
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment