Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Symfony/Component/Lock/Store/FlockStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public function __construct(string $lockPath = null)
if (null === $lockPath) {
$lockPath = sys_get_temp_dir();
}
if (!is_dir($lockPath) || !is_writable($lockPath)) {
throw new InvalidArgumentException(sprintf('The directory "%s" is not writable.', $lockPath));
if (!is_dir($lockPath)) {
if (false === @mkdir($lockPath, 0777, true) && !is_dir($lockPath)) {
throw new InvalidArgumentException(sprintf('The FlockStore directory "%s" does not exists and cannot be created.', $lockPath));
}
} elseif (!is_writable($lockPath)) {
throw new InvalidArgumentException(sprintf('The FlockStore directory "%s" is not writable.', $lockPath));
}

$this->lockPath = $lockPath;
Expand Down
15 changes: 12 additions & 3 deletions src/Symfony/Component/Lock/Tests/Store/FlockStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ protected function getStore(): PersistingStoreInterface
return new FlockStore();
}

public function testConstructWhenRepositoryDoesNotExist()
public function testConstructWhenRepositoryCannotBeCreated()
{
$this->expectException('Symfony\Component\Lock\Exception\InvalidArgumentException');
$this->expectExceptionMessage('The directory "/a/b/c/d/e" is not writable.');
$this->expectExceptionMessage('The FlockStore directory "/a/b/c/d/e" does not exists and cannot be created.');
if (!getenv('USER') || 'root' === getenv('USER')) {
$this->markTestSkipped('This test will fail if run under superuser');
}
Expand All @@ -46,14 +46,23 @@ public function testConstructWhenRepositoryDoesNotExist()
public function testConstructWhenRepositoryIsNotWriteable()
{
$this->expectException('Symfony\Component\Lock\Exception\InvalidArgumentException');
$this->expectExceptionMessage('The directory "/" is not writable.');
$this->expectExceptionMessage('The FlockStore directory "/" is not writable.');
if (!getenv('USER') || 'root' === getenv('USER')) {
$this->markTestSkipped('This test will fail if run under superuser');
}

new FlockStore('/');
}

public function testConstructWithSubdir()
{
if (!getenv('USER') || 'root' === getenv('USER')) {
$this->markTestSkipped('This test will fail if run under superuser');
}

new FlockStore(sys_get_temp_dir().'/sf-flock');
}

public function testSaveSanitizeName()
{
$store = $this->getStore();
Expand Down