Permalink
Browse files

Relative paths should be created relative to pwd.

If create() is called with a relative directory and the path does not
exist, it should be created inside of the folder->pwd() and not inside
the process' cwd.

Refs #4990
  • Loading branch information...
markstory committed Oct 28, 2014
1 parent ebc1bcb commit d228d83b1ee8f454cd92becb0fed47a6fa18db1e
Showing with 26 additions and 3 deletions.
  1. +16 −0 lib/Cake/Test/Case/Utility/FolderTest.php
  2. +10 −3 lib/Cake/Utility/Folder.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.
*
@@ -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;
}

0 comments on commit d228d83

Please sign in to comment.