[New-bugs-announce] [issue5220] os.makedirs' mode argument has bad default value

Joshua Bronson report at bugs.python.org
Wed Feb 11 21:36:11 CET 2009

New submission from Joshua Bronson <jabronson at gmail.com>:

os.makedirs' mode argument defaults to a hardcoded value of 511 (0777 in 
octal). This forces the caller to either pass in a different hardcoded value 
(commonly 0750), or to implement a workaround that calculates the expected 
mode based on the process owner's umask:

    umask, _ = subprocess.Popen(['sh', '-c', 'umask'],
    umask = int(umask, 8)
    mode = 0777 ^ umask
    os.makedirs(dir, mode)

Preferred behavior would be to have the mode default to the value which 
takes the umask into account rather than the hardcoded value 0777, so that 
directories would be created with the same permissions as e.g. files created 
via open(..).

N.B. I'm guessing the above workaround won't work on Windows (please excuse 
my poor Windows knowledge). All the more reason to have os.makedirs 
calculate the mode properly if none is given.

messages: 81666
nosy: jab
severity: normal
status: open
title: os.makedirs' mode argument has bad default value
versions: Python 2.4, Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list