FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Restore os.makedirs ability to apply mode to all directories created · Issue #86533 · python/cpython · GitHub

Repository navigation

Restore os.makedirs ability to apply mode to all directories created #86533

Closed

Description

BPO 42367
Nosy @gpshead, @tiran, @serhiy-storchaka, @ZackerySpytz, @JustAnotherArchivist, @kartiksubbarao
PRs
  • gh-86533: Restore os.makedirs() ability to apply *mode* recursively #23901
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2020-11-16.09:54:11.492>
    labels = ['type-feature', 'library', '3.11']
    title = 'Restore os.makedirs ability to apply mode to all directories created'
    updated_at = <Date 2021-11-22.21:16:30.185>
    user = 'https://github.com/gpshead'

    bugs.python.org fields:

    activity = <Date 2021-11-22.21:16:30.185>
    actor = 'gregory.p.smith'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-11-16.09:54:11.492>
    creator = 'gregory.p.smith'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42367
    keywords = ['patch', '3.7regression']
    message_count = 5.0
    messages = ['381082', '381084', '381086', '381087', '406802']
    nosy_count = 7.0
    nosy_names = ['gregory.p.smith', 'christian.heimes', 'serhiy.storchaka', 'ZackerySpytz', 'JustAnotherArchivist', 'kartiksubbarao', 'awtimmering']
    pr_nums = ['23901']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue42367'
    versions = ['Python 3.11']

    Linked PRs

    Activity

    1. gpshead commented on Nov 16, 2020

      MemberAuthor

      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 https://bugs.python.org/issue19930 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.

    2. added
      type-bugAn unexpected behavior, bug, or error
      stdlibStandard Library Python modules in the Lib/ directory
      on Nov 16, 2020
    3. gpshead commented on Nov 16, 2020

      MemberAuthor

      For consistency, pathlib.Path.mkdir should also gain this option.

    4. added
      type-featureA feature request or enhancement
      and removed
      type-bugAn unexpected behavior, bug, or error
      on Nov 16, 2020
    5. serhiy-storchaka commented on Nov 16, 2020

      Member

      Alternatively we can add an optional argument for the mode of intermediate directories.

      makedirs(name, mode=0o777, exist_ok=False, intermediate_mode=0o777)
    6. tiran commented on Nov 16, 2020

      Member

      +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
    7. 20 remaining items

    8. gpshead commented on May 18, 2026

      MemberAuthor

      @hugovk as 3.15 release manager: Would you consider the fix for this adding a new parent_mode=None keyword only argument to os.makedirs() and for use in pathlib.mkdir(..., parents=True) viable as a feature to add to 3.15? It is security related and we've had it open for ages as it exists to fix a it is security regression that shipped in 3.7. it doesn't change behavior, just adds a new optional keyword argument. I could make the argument that we should backport it to others given the security workarounds things like Django have had to adopt as a result (but they'll need to carry those anyways so probably best not to)... but adding it to 3.15beta2 seems uncontroversial and not likely to trip anyone up and avoids delaying yet another year. - #150011

    9. hugovk commented on May 18, 2026

      Member

      Yes, that's fine for 3.15beta2.

    10. added a commit that references this issue on May 18, 2026
    11. added 6 commits that reference this issue on May 18, 2026
    12. gpshead commented on May 19, 2026

      MemberAuthor

      thanks! this ships in 3.15beta2 onwards.

    13. added a commit that references this issue on Aug 28, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.15bugs and security fixessprintstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL