diff --git a/lib/Cake/Test/Case/Utility/FolderTest.php b/lib/Cake/Test/Case/Utility/FolderTest.php index fe1728da539..91c70e1ff91 100644 --- a/lib/Cake/Test/Case/Utility/FolderTest.php +++ b/lib/Cake/Test/Case/Utility/FolderTest.php @@ -170,6 +170,22 @@ public function testCreateWithTrailingDs() { $this->assertTrue($Folder->delete()); } +/** + * Test that relative paths to create() are added to cwd. + * + * @return void + */ + public function testCreateRelative() { + $folder = new Folder(TMP); + $path = TMP . 'tests' . DS . 'relative-test'; + $result = $folder->create('tests' . DS . 'relative-test'); + $this->assertTrue($result, 'should create'); + + $this->assertTrue(is_dir($path), 'Folder was not made'); + $folder = new Folder($path); + $folder->delete(); + } + /** * test recursive directory create failure. * diff --git a/lib/Cake/Utility/Folder.php b/lib/Cake/Utility/Folder.php index f84f0a39a01..a818c4817fb 100644 --- a/lib/Cake/Utility/Folder.php +++ b/lib/Cake/Utility/Folder.php @@ -487,10 +487,13 @@ public function tree($path = null, $exceptions = false, $type = null) { } /** - * Create a directory structure recursively. Can be used to create - * deep path structures like `/foo/bar/baz/shoe/horn` + * Create a directory structure recursively. * - * @param string $pathname The directory structure to create + * Can be used to create deep path structures like `/foo/bar/baz/shoe/horn` + * + * @param string $pathname The directory structure to create. Either an absolute or relative + * path. If the path is relative and exists in the process' cwd it will not be created. + * Otherwise relative paths will be prefixed with the current pwd(). * @param int $mode octal value 0755 * @return bool Returns TRUE on success, FALSE on failure * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::create @@ -500,6 +503,10 @@ public function create($pathname, $mode = false) { return true; } + if (!self::isAbsolute($pathname)) { + $pathname = self::addPathElement($this->pwd(), $pathname); + } + if (!$mode) { $mode = $this->mode; }