diff --git a/src/Caching/Storages/SQLiteJournal.php b/src/Caching/Storages/SQLiteJournal.php index b4f93e08..eef18867 100644 --- a/src/Caching/Storages/SQLiteJournal.php +++ b/src/Caching/Storages/SQLiteJournal.php @@ -38,6 +38,10 @@ private function open() throw new Nette\NotSupportedException('SQLiteJournal requires PHP extension pdo_sqlite which is not loaded.'); } + if ($this->path !== ':memory:' && !is_file($this->path)) { + touch($this->path); // ensures ordinary file permissions + } + $this->pdo = new \PDO('sqlite:' . $this->path); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->pdo->exec(' diff --git a/tests/Storages/SQLiteJournal.permissions.phpt b/tests/Storages/SQLiteJournal.permissions.phpt new file mode 100644 index 00000000..6ee97955 --- /dev/null +++ b/tests/Storages/SQLiteJournal.permissions.phpt @@ -0,0 +1,40 @@ +write('foo', []); + + Assert::same(0666, fileperms($file) & 0777); +}); + + +test(function () { + $file = TEMP_DIR . '/sqlitejournal.permissions.2.sqlite'; + Assert::false(file_exists($file)); + + umask(0077); + (new SQLiteJournal($file))->write('foo', []); + + Assert::same(0600, fileperms($file) & 0777); +});