Merge pull request #5001 from cakephp/issue-4990

Relative paths should be created relative to pwd.
This commit is contained in:
José Lorenzo Rodríguez 2014-10-28 14:20:30 +01:00
commit a0aac5cfa9
2 changed files with 26 additions and 3 deletions

View file

@ -170,6 +170,22 @@ class FolderTest extends CakeTestCase {
$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.
*

View file

@ -487,10 +487,13 @@ class Folder {
}
/**
* 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 @@ class Folder {
return true;
}
if (!self::isAbsolute($pathname)) {
$pathname = self::addPathElement($this->pwd(), $pathname);
}
if (!$mode) {
$mode = $this->mode;
}