From a710238273a5a5d5342a10f79fa9c3eab447b4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hrani=C4=8Dka?= Date: Tue, 9 Aug 2016 22:25:59 +0200 Subject: [PATCH] SQLiteStorage: filesystem permissions like ordinary file (#44) --- src/Caching/Storages/SQLiteStorage.php | 4 ++ tests/Storages/SQLiteStorage.permissions.phpt | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/Storages/SQLiteStorage.permissions.phpt 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); +});