[issue5220] os.makedirs' mode argument has bad default value

Martin v. Löwis report at bugs.python.org
Wed Feb 11 22:47:09 CET 2009


Martin v. Löwis <martin at v.loewis.de> added the comment:

> My misunderstanding stemmed from recently coming across two widely-used 
> packages which both pass mode=0750 to os.makedirs. I have no idea why 
> they would be doing this (as it effectively throws away part of the 
> umask), unless they too are misunderstanding the mode parameter.

You use such a mode if you want the resulting directory definitely not
world-readable, and definitely not group-writable, despite what umask
the user running the program may have set.

A common case is installation programs, where the installer wants to
create directories independent of the umask root may have set when
running the installer.

> My 
> suspicion is that the mode parameter is widely misunderstood to mean the 
> desired permissions of the created directory. I have filed tickets in 
> the packages in which I came across this to make sure they're doing what 
> they intend.

My suspicion is that people setting explicit file permissions typically
know what they are doing, and that you will find that your tickets get
closed as invalid, explaining to you that this mode usage is fully
intentional.

> Could the __doc__ for os.mkdir and os.makedirs be expanded to make this 
> clearer?

I'm skeptical that this should be necessary. Whoever explained umask to
you should have mentioned how it really works (i.e. that it is built
into and considered by the operating system every time a file or
directory is created).

By the same pattern, the doc string of mkdir should also explain what
relative file names are and how the current directory affects their
interpretation. IMO, the doc string shouldn't teach fundamental system
principles.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5220>
_______________________________________


More information about the Python-bugs-list mailing list