Skip to content

Commit

Permalink
Merge pull request #620 from nicolasmure/fix/do-not-create-local-dire…
Browse files Browse the repository at this point in the history
…ctory-automatically

[1.0] Do not automatically create the base directory for Local adapter
  • Loading branch information
nicolasmure authored Jul 1, 2019
2 parents a18a6f7 + b7a7bea commit a93e739
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spec/Gaufrette/Adapter/LocalSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ function it_is_a_mime_type_provider()
$this->shouldHaveType('Gaufrette\Adapter\MimeTypeProvider');
}

function it_throws_when_the_base_directory_does_not_exist()
{
$this->beConstructedWith('/do-no-exists');

$this->shouldThrow(StorageFailure::class)->duringInstantiation();
}

function it_gets_the_file_mime_type()
{
$this->mimeType('filename')->shouldReturn('text/plain');
Expand Down
7 changes: 6 additions & 1 deletion src/Gaufrette/Adapter/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
class Local implements Adapter, StreamFactory, ChecksumCalculator, SizeCalculator, MimeTypeProvider
{
protected $directory;
private $create;
private $mode;

/**
Expand All @@ -33,6 +32,12 @@ public function __construct($directory, $mode = 0777)
if (is_link($this->directory)) {
$this->directory = realpath($this->directory);
}

if (!is_dir($this->directory)) {
throw new StorageFailure(
sprintf('Directory "%s" does not exist.', $directory)
);
}
}

/**
Expand Down

0 comments on commit a93e739

Please sign in to comment.