Skip to content

[Lock] Create flock directory #39701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2021
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