Skip to content

Commit

Permalink
Fixed #64: Ensure parent directory on writeStream
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Feb 1, 2014
1 parent 9a4e4ab commit 073bcbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/League/Flysystem/Adapter/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,13 @@ public function writeStream($path, $resource, $config = null)
{
rewind($resource);
$config = Util::ensureConfig($config);
$location = $this->prefix($path);

if ( ! $stream = fopen($this->prefix($path), 'w+')) {
if ( ! is_dir($dirname = dirname($location))) {
mkdir($dirname, 0777, true);
}

if ( ! $stream = fopen($location, 'w+')) {
return false;
}

Expand All @@ -134,8 +139,9 @@ public function writeStream($path, $resource, $config = null)
return false;
}

if ($visibility = $config->get('visibility'))
if ($visibility = $config->get('visibility')) {
$this->setVisibility($path, $visibility);
}

return compact('path', 'visibility');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/LocalAdapterTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public function testWriteStream()
$temp = tmpfile();
fwrite($temp, 'dummy');
rewind($temp);
$adapter->writeStream('file.txt', $temp);
$adapter->writeStream('dir/file.txt', $temp);
fclose($temp);
$this->assertTrue($adapter->has('file.txt'));
$result = $adapter->read('file.txt');
$this->assertTrue($adapter->has('dir/file.txt'));
$result = $adapter->read('dir/file.txt');
$this->assertEquals('dummy', $result['contents']);
$adapter->delete('file.txt');
$adapter->delete('dir/file.txt');
}

public function testUpdateStream()
Expand Down

0 comments on commit 073bcbd

Please sign in to comment.