Skip to content

Commit

Permalink
Merge pull request #5001 from cakephp/issue-4990
Browse files Browse the repository at this point in the history
Relative paths should be created relative to pwd.
  • Loading branch information
lorenzo committed Oct 28, 2014
2 parents ebc1bcb + d228d83 commit a0aac5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Utility/FolderTest.php
Expand Up @@ -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.
*
Expand Down
13 changes: 10 additions & 3 deletions lib/Cake/Utility/Folder.php
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit a0aac5c

Please sign in to comment.