Skip to content

Respect the process umask when creating the cache directory - #375

Open
hikmetba-bit wants to merge 1 commit into
grantjenks:masterfrom
hikmetba-bit:fix/332-respect-umask-cache-dir
Open

hikmetba-bit wants to merge 1 commit into
grantjenks:masterfrom
hikmetba-bit:fix/332-respect-umask-cache-dir

Conversation

@hikmetba-bit

Copy link
Copy Markdown

Summary

Fixes #332.

Cache.__init__ creates the cache directory with os.makedirs(directory, 0o755). Since the mode passed to os.makedirs() is hard-coded, the OS's umask can only ever clear bits from it (mode & ~umask) — it can never restore bits that 0o755 has already dropped. So a caller with e.g. umask 000 (expecting world-writable directories, as with any other directory they create) still gets rwxr-xr-x for the cache directory, with no way to change that short of chmod-ing it afterward.

Fix

Drop the explicit mode and call os.makedirs(directory). os.makedirs()'s own default mode is 0o777, 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_umask to tests/test_core.py, asserting os.makedirs is called with only the directory argument (no explicit mode), following the existing test_init_makedirs pattern in the same file.

Ran locally: pytest tests/test_core.py tests/test_fanout.py — 130 passed, including the new test and the existing test_init_makedirs (which still passes since it only asserts on OSError handling, unaffected by dropping the mode argument).

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

umask settings ignored in cache directory creation

1 participant