diff --git a/src/Caching/Storages/SQLiteStorage.php b/src/Caching/Storages/SQLiteStorage.php index 3f0d552d..bef1a106 100644 --- a/src/Caching/Storages/SQLiteStorage.php +++ b/src/Caching/Storages/SQLiteStorage.php @@ -22,6 +22,10 @@ class SQLiteStorage extends Nette\Object implements Nette\Caching\IStorage public function __construct($path = ':memory:') { + if ($path !== ':memory:' && !is_file($path)) { + touch($path); // ensures ordinary file permissions + } + $this->pdo = new \PDO('sqlite:' . $path); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->pdo->exec(' diff --git a/tests/Storages/SQLiteStorage.permissions.phpt b/tests/Storages/SQLiteStorage.permissions.phpt new file mode 100644 index 00000000..7c036b31 --- /dev/null +++ b/tests/Storages/SQLiteStorage.permissions.phpt @@ -0,0 +1,40 @@ +write('foo', 'bar', []); + + Assert::same(0666, fileperms($file) & 0777); +}); + + +test(function () { + $file = TEMP_DIR . '/sqlitestorage.permissions.2.sqlite'; + Assert::false(file_exists($file)); + + umask(0077); + (new SQLiteStorage($file))->write('foo', 'bar', []); + + Assert::same(0600, fileperms($file) & 0777); +});