Skip to content

Commit

Permalink
Do not automatically create the base directory for Local adapter
Browse files Browse the repository at this point in the history
Related to KnpLabs#618

We throw an exception when building the adapter if the specified base
directory does not exist. The write methods can still create sub
directories (eg /base/my/very/deep/dir), however the /base directory
have to be present.

The developer should create this directory on its own before using the
adapter.
  • Loading branch information
nicolasmure committed Jun 28, 2019
1 parent 15d250c commit b7a7bea
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 @@ -33,6 +33,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 @@ -23,7 +23,6 @@ class Local implements Adapter,
MimeTypeProvider
{
protected $directory;
private $create;
private $mode;

/**
Expand All @@ -39,6 +38,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 b7a7bea

Please sign in to comment.