Create flock directory

This commit is contained in:
Jérémy Derussé 2021-01-03 19:16:03 +01:00
parent e970027682
commit be22c37ea1
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
2 changed files with 18 additions and 5 deletions

View File

@ -42,8 +42,12 @@ class FlockStore implements BlockingStoreInterface, SharedLockStoreInterface
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;

View File

@ -32,10 +32,10 @@ class FlockStoreTest extends AbstractStoreTest
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');
}
@ -46,7 +46,7 @@ class FlockStoreTest extends AbstractStoreTest
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');
}
@ -54,6 +54,15 @@ class FlockStoreTest extends AbstractStoreTest
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();