Respect the process umask when creating the cache directory - #375
Open
hikmetba-bit wants to merge 1 commit into
Open
hikmetba-bit wants to merge 1 commit into
hikmetba-bit wants to merge 1 commit into
Conversation
Cache.__init__ created the cache directory with os.makedirs(directory, 0o755), which hard-codes the permission bits instead of letting the OS apply the umask like it does for any other newly created directory. Since umask can only clear bits (mode & ~umask), passing an explicit 0o755 caps the directory at rwxr-xr-x no matter what umask the caller has configured (e.g. umask 000 expecting world-writable directories). Drop the explicit mode so os.makedirs() uses its default (0o777), which the OS then masks with the umask as usual. Fixes grantjenks#332 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #332.
Cache.__init__creates the cache directory withos.makedirs(directory, 0o755). Since the mode passed toos.makedirs()is hard-coded, the OS's umask can only ever clear bits from it (mode & ~umask) — it can never restore bits that0o755has already dropped. So a caller with e.g.umask 000(expecting world-writable directories, as with any other directory they create) still getsrwxr-xr-xfor the cache directory, with no way to change that short ofchmod-ing it afterward.Fix
Drop the explicit mode and call
os.makedirs(directory).os.makedirs()'s own default mode is0o777, which the OS then masks with the process umask exactly like it does for directories created by any other call — this is what the issue is asking for ("use the default permissions provided by the OS").Test plan
Added
test_init_makedirs_respects_umasktotests/test_core.py, assertingos.makedirsis called with only the directory argument (no explicit mode), following the existingtest_init_makedirspattern in the same file.Ran locally:
pytest tests/test_core.py tests/test_fanout.py— 130 passed, including the new test and the existingtest_init_makedirs(which still passes since it only asserts onOSErrorhandling, unaffected by dropping the mode argument).🤖 Generated with Claude Code