Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLiteJournal permissions #29

Closed
milo opened this issue Aug 2, 2015 · 5 comments
Closed

SQLiteJournal permissions #29

milo opened this issue Aug 2, 2015 · 5 comments

Comments

@milo
Copy link
Member

@milo milo commented Aug 2, 2015

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

#28 (comment)

@milo

This comment has been minimized.

Copy link
Member Author

@milo milo commented Aug 12, 2015

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

This comment has been minimized.

Copy link
Member Author

@milo milo commented Aug 12, 2015

The code

        if (strcmp($path, ':memory:') !== 0 && !is_file($path)) {
            fclose(fopen($path, 'w'));
            chmod($path, 0666 & (~umask()));
        }

seems to work.

milo added a commit to milo/nette-caching that referenced this issue Aug 16, 2015
milo added a commit to milo/nette-caching that referenced this issue Sep 7, 2015
milo added a commit to milo/nette-caching that referenced this issue Oct 17, 2015
milo added a commit to milo/nette-caching that referenced this issue Apr 3, 2016
@milo milo closed this in 73d31b8 Apr 3, 2016
@hranicka

This comment has been minimized.

Copy link
Contributor

@hranicka hranicka commented Jul 31, 2016

@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

This comment has been minimized.

Copy link
Member

@dg dg commented Jul 31, 2016

ok

dg added a commit that referenced this issue Jul 31, 2016
@hranicka

This comment has been minimized.

Copy link
Contributor

@hranicka hranicka commented Jul 31, 2016

@dg Thank you David. You're super 👍

Have a nice sunday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.