File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,10 @@ public function __construct($path)
37
37
38
38
private function open ()
39
39
{
40
+ if ($ this ->path !== ':memory: ' && !is_file ($ this ->path )) {
41
+ touch ($ this ->path ); // ensures ordinary file permissions
42
+ }
43
+
40
44
$ this ->pdo = new \PDO ('sqlite: ' . $ this ->path );
41
45
$ this ->pdo ->setAttribute (\PDO ::ATTR_ERRMODE , \PDO ::ERRMODE_EXCEPTION );
42
46
$ this ->pdo ->exec ('
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * Test: Nette\Caching\Storages\SQLiteJournal database file permissions.
5
+ */
6
+
7
+ use Nette \Caching \Storages \SQLiteJournal ;
8
+ use Tester \Assert ;
9
+
10
+
11
+ require __DIR__ . '/../bootstrap.php ' ;
12
+
13
+
14
+ if (!extension_loaded ('pdo_sqlite ' )) {
15
+ Tester \Environment::skip ('Requires PHP extension pdo_sqlite. ' );
16
+ } elseif (defined ('PHP_WINDOWS_VERSION_BUILD ' )) {
17
+ Tester \Environment::skip ('UNIX test only. ' );
18
+ }
19
+
20
+
21
+ test (function () {
22
+ $ file = TEMP_DIR . '/sqlitejournal.permissions.1.sqlite ' ;
23
+ Assert::false (file_exists ($ file ));
24
+
25
+ umask (0 );
26
+ (new SQLiteJournal ($ file ))->write ('foo ' , []);
27
+
28
+ Assert::same (0666 , fileperms ($ file ) & 0777 );
29
+ });
30
+
31
+
32
+ test (function () {
33
+ $ file = TEMP_DIR . '/sqlitejournal.permissions.2.sqlite ' ;
34
+ Assert::false (file_exists ($ file ));
35
+
36
+ umask (0077 );
37
+ (new SQLiteJournal ($ file ))->write ('foo ' , []);
38
+
39
+ Assert::same (0600 , fileperms ($ file ) & 0777 );
40
+ });
You can’t perform that action at this time.
0 commit comments