Skip to content

Commit

Permalink
Fixes #17: Ensure the root directory exists in the Local adapter.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Nov 17, 2013
1 parent ca0783d commit f30b222
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/Flysystem/Adapter/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,26 @@ class Local extends AbstractAdapter
*/
public function __construct($root)
{
$root = realpath($root);
$root = $this->ensureRootDirectory($root);

$this->root = Util::normalizePrefix($root, DIRECTORY_SEPARATOR);
}

/**
* Ensure the root directory exists.
*
* @param string $root root directory path
* @return string real path to root
*/
protected function ensureRootDirectory($root)
{
if ( ! is_dir($root)) {
mkdir($root, 0777, true);
}

return realpath($root);
}

/**
* Prefix a path with the root
*
Expand Down
2 changes: 1 addition & 1 deletion tests/FilesystemTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function metaProvider()

public function testInstantiable()
{
$instance = new Filesystem($adapter = new Adapter\Local(__DIR__.'files'), $cache = new Cache\Memory);
$instance = new Filesystem($adapter = new Adapter\Local(__DIR__.'/files/deeper'), $cache = new Cache\Memory);
}

public function filesystemProvider()
Expand Down

0 comments on commit f30b222

Please sign in to comment.