File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
src/Symfony/Component/Lock Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,12 @@ public function __construct(string $lockPath = null)
42
42
if (null === $ lockPath ) {
43
43
$ lockPath = sys_get_temp_dir ();
44
44
}
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 ));
47
51
}
48
52
49
53
$ this ->lockPath = $ lockPath ;
Original file line number Diff line number Diff line change @@ -32,10 +32,10 @@ protected function getStore(): PersistingStoreInterface
32
32
return new FlockStore ();
33
33
}
34
34
35
- public function testConstructWhenRepositoryDoesNotExist ()
35
+ public function testConstructWhenRepositoryCannotBeCreated ()
36
36
{
37
37
$ 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 . ' );
39
39
if (!getenv ('USER ' ) || 'root ' === getenv ('USER ' )) {
40
40
$ this ->markTestSkipped ('This test will fail if run under superuser ' );
41
41
}
@@ -46,14 +46,23 @@ public function testConstructWhenRepositoryDoesNotExist()
46
46
public function testConstructWhenRepositoryIsNotWriteable ()
47
47
{
48
48
$ this ->expectException ('Symfony\Component\Lock\Exception\InvalidArgumentException ' );
49
- $ this ->expectExceptionMessage ('The directory "/" is not writable. ' );
49
+ $ this ->expectExceptionMessage ('The FlockStore directory "/" is not writable. ' );
50
50
if (!getenv ('USER ' ) || 'root ' === getenv ('USER ' )) {
51
51
$ this ->markTestSkipped ('This test will fail if run under superuser ' );
52
52
}
53
53
54
54
new FlockStore ('/ ' );
55
55
}
56
56
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
+
57
66
public function testSaveSanitizeName ()
58
67
{
59
68
$ store = $ this ->getStore ();
You can’t perform that action at this time.
0 commit comments