nette/caching

SQLiteJournal permissions

milo opened this issue ยท 5 comments

milo commented

To be consistent with FileJournal, SQLite database should have 0666 - umask() permissions.

#28 (comment)

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.

@milo Thank you for this!

@dg Please, can you back-port this into v2.4?

When I purge my temp/cache directory, created SQLite file has another permissions than other files.

nette/caching v2.5 requires nette/utils v2.4 and our applications do not support it yet.

dg commented

ok

@dg Thank you David. You're super ๐Ÿ‘

Have a nice sunday.