Skip to content

gh-86533: Restore os.makedirs() ability to apply *mode* recursively#23901

Open
ZackerySpytz wants to merge 12 commits intopython:mainfrom
ZackerySpytz:bpo-42367-makedirs-dir-mode
Open

gh-86533: Restore os.makedirs() ability to apply *mode* recursively#23901
ZackerySpytz wants to merge 12 commits intopython:mainfrom
ZackerySpytz:bpo-42367-makedirs-dir-mode

Conversation

@ZackerySpytz
Copy link
Copy Markdown
Contributor

@ZackerySpytz ZackerySpytz commented Dec 22, 2020

Allow os.makedirs() to set the mode of intermediate directories that are created. This adds a parent_mode argument to allow explicitly setting those modes instead of inheriting from the
umask.

Also adds the equivalent feature to pathlib.Path.mkdir for consistency as noted in the issue.

https://bugs.python.org/issue42367

Allow os.makedirs() to apply the *mode* argument to any intermediate
directories that are created.
@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jan 22, 2021
@ZackerySpytz
Copy link
Copy Markdown
Contributor Author

It is not stale.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jan 23, 2021
@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 23, 2021
@chimosky
Copy link
Copy Markdown

chimosky commented Jul 8, 2021

@ZackerySpytz is there any workaround for this at the moment as you stated in #42367 that umask can't be used to control the intermediate directory creation permissions.

MaxwellDupre

This comment was marked as outdated.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Aug 2, 2022
@erlend-aasland erlend-aasland changed the title bpo-42367: Restore os.makedirs() ability to apply *mode* recursively gh-86533: Restore os.makedirs() ability to apply *mode* recursively Jan 5, 2024
vanschelven added a commit to bugsink/bugsink that referenced this pull request Aug 29, 2025
Defends against certain forms of local privilege escalation, i.e.
understood to be defense in depth rather than a security issue given
the recommended ways of deploying (docker container or in a single-use
single-server)

Fix #174

See python/cpython#23901
gpshead and others added 2 commits August 30, 2025 06:39
- Replace recursive_mode with more intuitive parent_mode parameter
- parent_mode=None (default): intermediate dirs use default permissions
- parent_mode=<mode>: intermediate dirs use specified permissions
- parent_mode=mode: matches Python 3.6 behavior
- Update documentation with version markers and usage examples
- Add comprehensive test coverage with separate focused test functions
- Fix test permissions to avoid cleanup issues (0o555 → 0o705)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add parent_mode parameter to Path.mkdir() for specifying intermediate
  directory permissions when parents=True
- Maintain pathlib's independence by using recursive implementation
  rather than delegating to os.makedirs
- Add comprehensive tests including umask behavior verification
- Update documentation and whatsnew entries
- Provides consistency with os.makedirs parent_mode parameter

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@gpshead gpshead force-pushed the bpo-42367-makedirs-dir-mode branch from 3cc6495 to 67ae3af Compare August 30, 2025 08:06
@gpshead gpshead self-assigned this Aug 30, 2025
Use st_mode & 0o777 masking instead of stat.S_IMODE() to ignore
filesystem-specific bits like setgid, matching the approach used
in os.makedirs tests.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
vanschelven added a commit to bugsink/bugsink that referenced this pull request Aug 30, 2025
Defends against certain forms of local privilege escalation, i.e.
understood to be defense in depth rather than a security issue given
the recommended ways of deploying (docker container or in a single-use
single-server)

Fix #174

See python/cpython#23901
Copy link
Copy Markdown
Contributor Author

@ZackerySpytz ZackerySpytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, @gpshead. I see that you have made some changes to this PR. I have pointed out some lines in the changes you have made that we should modify.

We should also make sure that the lines in the new pathlib code are limited to a maximum of 79 characters (for PEP 8 compliance).

gpshead and others added 5 commits August 31, 2025 01:20
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants