Twig icon indicating copy to clipboard operation
Twig copied to clipboard

[FR] `dirMode` and `fileMode` options for FilesystemCache

Open brandonkelly opened this issue 2 years ago • 7 comments

Currently FilesystemCache creates directories with 777 permissions, and PHP files with 666 permissions. It would be nice if new dirMode and fileMode options were supported, which could be used to override those default permissions.

brandonkelly avatar Apr 05 '23 18:04 brandonkelly

I think the current code is reasonable. We're doing the same in Symfony as well. Note that the mode is affected by the umask. So, it's not necessarily 0777. You can call umask() to change the permissions.

if new dirMode and fileMode options were supported -> I'm not sure what you're referring to here?

fabpot avatar Sep 12 '24 05:09 fabpot

if new dirMode and fileMode options were supported -> I'm not sure what you're referring to here?

I was suggesting that Twig could add new dirMode and fileMode options, giving us a way to set the permissions programmatically when initializing the Twig environment.

brandonkelly avatar Sep 15 '24 07:09 brandonkelly

Would you agree that using umask() is enough?

fabpot avatar Sep 15 '24 09:09 fabpot

Any feedback on my suggestion @brandonkelly?

fabpot avatar Feb 08 '25 13:02 fabpot

What about not setting any permission at all and just creating the directories and files?

ericmorand avatar Feb 08 '25 15:02 ericmorand

@fabpot I don’t think umask() would help in our case.

Several libraries that work with files have dirMode/dirPermission and fileMode/filePermission settings (e.g. RotatingFileHandler in Monolog), so Craft has defaultDirMode and defaultFileMode config settings, and the hope is that those could apply to directories and files created by Twig as well.

brandonkelly avatar Feb 10 '25 15:02 brandonkelly

(Sorry, didn’t mean to close the issue. Rogue trackpad click!)

brandonkelly avatar Feb 10 '25 15:02 brandonkelly