Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be22c37

Browse files
committed
Create flock directory
1 parent e970027 commit be22c37

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/Symfony/Component/Lock/Store/FlockStore.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ public function __construct(string $lockPath = null)
4242
if (null === $lockPath) {
4343
$lockPath = sys_get_temp_dir();
4444
}
45-
if (!is_dir($lockPath) || !is_writable($lockPath)) {
46-
throw new InvalidArgumentException(sprintf('The directory "%s" is not writable.', $lockPath));
45+
if (!is_dir($lockPath)) {
46+
if (false === @mkdir($lockPath, 0777, true) && !is_dir($lockPath)) {
47+
throw new InvalidArgumentException(sprintf('The FlockStore directory "%s" does not exists and cannot be created.', $lockPath));
48+
}
49+
} elseif (!is_writable($lockPath)) {
50+
throw new InvalidArgumentException(sprintf('The FlockStore directory "%s" is not writable.', $lockPath));
4751
}
4852

4953
$this->lockPath = $lockPath;

src/Symfony/Component/Lock/Tests/Store/FlockStoreTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ protected function getStore(): PersistingStoreInterface
3232
return new FlockStore();
3333
}
3434

35-
public function testConstructWhenRepositoryDoesNotExist()
35+
public function testConstructWhenRepositoryCannotBeCreated()
3636
{
3737
$this->expectException('Symfony\Component\Lock\Exception\InvalidArgumentException');
38-
$this->expectExceptionMessage('The directory "/a/b/c/d/e" is not writable.');
38+
$this->expectExceptionMessage('The FlockStore directory "/a/b/c/d/e" does not exists and cannot be created.');
3939
if (!getenv('USER') || 'root' === getenv('USER')) {
4040
$this->markTestSkipped('This test will fail if run under superuser');
4141
}
@@ -46,14 +46,23 @@ public function testConstructWhenRepositoryDoesNotExist()
4646
public function testConstructWhenRepositoryIsNotWriteable()
4747
{
4848
$this->expectException('Symfony\Component\Lock\Exception\InvalidArgumentException');
49-
$this->expectExceptionMessage('The directory "/" is not writable.');
49+
$this->expectExceptionMessage('The FlockStore directory "/" is not writable.');
5050
if (!getenv('USER') || 'root' === getenv('USER')) {
5151
$this->markTestSkipped('This test will fail if run under superuser');
5252
}
5353

5454
new FlockStore('/');
5555
}
5656

57+
public function testConstructWithSubdir()
58+
{
59+
if (!getenv('USER') || 'root' === getenv('USER')) {
60+
$this->markTestSkipped('This test will fail if run under superuser');
61+
}
62+
63+
new FlockStore(sys_get_temp_dir().'/sf-flock');
64+
}
65+
5766
public function testSaveSanitizeName()
5867
{
5968
$store = $this->getStore();

0 commit comments

Comments
 (0)