SQLiteJournal permissions
milo opened this issue ยท 5 comments
milo commented
To be consistent with FileJournal, SQLite database should have 0666 - umask()
permissions.
milo commented
I'm trying following fix (search for chmod):
public function __construct($path = ':memory:')
{
if (!extension_loaded('pdo_sqlite')) {
throw new Nette\NotSupportedException('SQLiteJournal ...');
}
$chmod = strcmp($path, ':memory:') !== 0 && !is_file($path);
$this->pdo = new \PDO('sqlite:' . $path, NULL, NULL, [\PDO::ATTR_PERSISTENT => TRUE]);
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->pdo->exec('
PRAGMA foreign_keys = ON;
...
CREATE INDEX IF NOT EXISTS idx_priorities_priority ON priorities(priority);
');
if ($chmod) {
chmod($path, 0666 & (~umask()));
}
}
but getting E_WARNING: chmod(): No such file or directory
. I guess, file is created in memory at first. Didn't find any PRAGMA
to force flush. Maybe some transaction can do that, but that's strange.
milo commented
The code
if (strcmp($path, ':memory:') !== 0 && !is_file($path)) {
fclose(fopen($path, 'w'));
chmod($path, 0666 & (~umask()));
}
seems to work.
hranicka commented
dg commented
ok