[Python-Dev] PEP 3147, pycache directories and umask (original) (raw)

Cameron Simpson cs at zip.com.au
Tue Mar 23 01:40:02 CET 2010


On 22Mar2010 09:56, Barry Warsaw <barry at python.org> wrote: | I have a pretty good start on PEP 3147 implementation [1], but I've | encountered a situation that I'd like to get some feedback on. Here's the | test case illustrating the problem. From testimport.py: || def testwritabledirectory(self): | # The umask is not conducive to creating a writable pycache | # directory. | with umask(0o222): [...] | The pycache directory does not exist before the import, and the import | machinery creates the directory, but the umask leaves the directory unwritable | by anybody. So of course when the import machinery goes to write the .pyc | file inside pycache, it fails. This does not cause an ImportError though, | just like if today the package directory were unwritable. || This might be different than today's situation though because once the | unwritable pycache directory is created, nothing is going to change that | without explicit user interaction, and that might be difficult after the | fact.

Like any bad/suboptimal permission.

| I'm not sure what the right answer is. Some possible choices: || * Tough luck

+1 I'd go with this one myself.

| * Force the umask so that the directory is writable, but then the question is, | by whom? ugo+w or something less?

-2 Racy and dangerous. The umask is a UNIX process global, and other threads may get bad results if they're active during this window.

| * Copy the permissions from the parent directory and ignore umask

-1 Maybe. But consider that you may not be the owner of the parent: then the new child will have different ownership than the parent but the same permission mask. Potentially a bad mix. This approach is very hard to get right.

| * Raise an exception or refuse to create pycache if it's not writable | (again, by whom?)

-3 Bleah. My python program won't run because an obscure (to the user) directory had unusual permissions?

Tough ove, it's the only way:-)

Cameron Simpson <cs at zip.com.au> DoD#743 http://www.cskk.ezoshosting.com/cs/

When asked what would I most want to try before doing it, I said Death. - Michael Burton, michaelb at compnews.co.uk



More information about the Python-Dev mailing list