Skip to content

Commit a93e739

Browse files
authored
Merge pull request #620 from nicolasmure/fix/do-not-create-local-directory-automatically
[1.0] Do not automatically create the base directory for Local adapter
2 parents a18a6f7 + b7a7bea commit a93e739

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spec/Gaufrette/Adapter/LocalSpec.php

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ function it_is_a_mime_type_provider()
3232
$this->shouldHaveType('Gaufrette\Adapter\MimeTypeProvider');
3333
}
3434

35+
function it_throws_when_the_base_directory_does_not_exist()
36+
{
37+
$this->beConstructedWith('/do-no-exists');
38+
39+
$this->shouldThrow(StorageFailure::class)->duringInstantiation();
40+
}
41+
3542
function it_gets_the_file_mime_type()
3643
{
3744
$this->mimeType('filename')->shouldReturn('text/plain');

src/Gaufrette/Adapter/Local.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
class Local implements Adapter, StreamFactory, ChecksumCalculator, SizeCalculator, MimeTypeProvider
1919
{
2020
protected $directory;
21-
private $create;
2221
private $mode;
2322

2423
/**
@@ -33,6 +32,12 @@ public function __construct($directory, $mode = 0777)
3332
if (is_link($this->directory)) {
3433
$this->directory = realpath($this->directory);
3534
}
35+
36+
if (!is_dir($this->directory)) {
37+
throw new StorageFailure(
38+
sprintf('Directory "%s" does not exist.', $directory)
39+
);
40+
}
3641
}
3742

3843
/**

0 commit comments

Comments
 (0)