Title: Restore os.makedirs ability to apply mode to all directories created
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: JustAnotherArchivist, ZackerySpytz, christian.heimes, gregory.p.smith, serhiy.storchaka
Priority: normal Keywords: 3.7regression, patch

Created on 2020-11-16 09:54 by gregory.p.smith, last changed 2021-05-05 01:22 by JustAnotherArchivist.

Pull Requests
URL Status Linked Edit
PR 23901 open ZackerySpytz, 2020-12-22 23:58
Messages (4)
msg381082 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2020-11-16 09:54
os.makedirs used to pass its mode argument on down recursively so that every level of directory it created would have the specified permissions.

That was removed in Python 3.7 as as if it were a mis-feature.  Maybe it was in one situation, but it was also a desirable *feature*.  It wasn't a bug.

We've got 15 year old code depending on that and the only solution for it to work on Python 3.7-3.9 is to reimplement recursive directory creation. :(

This feature needs to be brought back.  Rather than flip flop on the API, adding an flag to indicate if the permissions should be applied recursively or not seems like the best way forward.

The "workaround" documented in the above bug is invalid.  umask cannot be used to control the intermediate directory creation permissions as that is a process wide global that would impact other threads or signal handlers.  umask also cannot be used as umask does not allow setting of special bits such as stat.S_ISVTX.

result: Our old os.makedirs() code that tried to set the sticky bit (ISVTX) on all directories now fails to set it at all levels.
msg381084 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2020-11-16 10:01
For consistency, pathlib.Path.mkdir should also gain this option.
msg381086 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-11-16 10:32
Alternatively we can add an optional argument for the mode of intermediate directories.

makedirs(name, mode=0o777, exist_ok=False, intermediate_mode=0o777)
msg381087 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-11-16 10:36
+1 for restoring the feature

+0 for Serhiy's proposal iff intermediate_mode defaults to the value of mode:

    def makedirs(name, mode=0o777, exist_ok=False, *, intermediate_mode=None):
        if intermediate_mode is None:
            intermediate_mode = mode
Date User Action Args
2021-05-05 01:22:10JustAnotherArchivistsetnosy: + JustAnotherArchivist
2020-12-22 23:58:03ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request22756
stage: needs patch -> patch review
2020-11-16 10:36:36christian.heimessetnosy: + christian.heimes
messages: + msg381087
2020-11-16 10:32:46serhiy.storchakasetmessages: + msg381086
2020-11-16 10:01:31gregory.p.smithsettype: behavior -> enhancement
2020-11-16 10:01:17gregory.p.smithsetmessages: + msg381084
2020-11-16 09:54:11gregory.p.smithcreate