Repository navigation
fix(mkdir): wire -m through a directory-applying mode path; fix omitted-who '=' umask leak (main CI red) - #1564
Merged
Merged
Conversation
…#1488) The wave1 wiring routed mkdir -m through modemap::apply_mode, whose documented contract skips directories ("Windows ignores read-only on dirs") - the chmod flavor. The pre-wiring C++ pilot landed the attribute on the created directory (apply_directory_mode, 3a8e0f9), so the three wiring acceptance tests went red on CI (run 42878813093): mkdir_mode_readonly_sets_windows_attribute, mkdir_parents_mode_applies_to_leaf_only, mkdir_mode_1330_symbolic - the latter failing exactly at EXPECT_TRUE(run_mkdir(L"a-w", L"e")). [GNU] coreutils src/mkdir.c main() applies the compiled mode to the created leaf DIRECTORY itself: options.mode = mode_adjust(S_IRWXUGO, true, umask_value, change, &options.mode_bits); gnulib lib/mkdir-p.c:88 make_dir_parents ends with an explicit dirchownmod(..., mode, mode_bits) chmod of the leaf, so the umask can never leak into the -m result (options.umask_self only shapes the raw mkdir call). Ancestors go through mkdir.c make_ancestor -> mkdir(component, S_IRWXUGO) under umask_ancestor = umask & ~(S_IWUSR | S_IXUSR): default mode, never -m. Fix: add modemap::apply_mode_dir (owner-write bit -> FILE_ATTRIBUTE_READONLY on directories too - the attribute gates directory deletion on NTFS) and use it in create_one / create_parents_walk. chmod's apply_mode contract is untouched. Also fix the shared evaluator's who-omitted '=': it preserved the umask-masked base bits. [GNU] gnulib lib/modechange.c:340 mode_adjust '=' branch: preserved = (affected ? ~affected : 0) | omit_change - a who-omitted '=' keeps NOTHING outside value ("Otherwise, clear all the bits"). WSL coreutils 9.4 oracle under umask 077: mkdir -m =r -> 400 (modemap produced 477), -m =w -> 200, -m +w -> 777; chmod =r on a 666 file -> 400, =w -> 200. Identical behavior at umask 0, so all existing tests and gates are unaffected. Tests: - mkdir: mode_persists_readonly_attribute_on_leaf, parents_mode_applies_to_leaf_only_readonly, explicit_mode_ignores_process_umask (CRT _umask(077) window: numeric -m lands exactly despite the umask; who-omitted symbolic stays umask-gated, matching mode_adjust). - modemap: eq_omitted_who_clears_umask_masked_bits. - Differential gate: mkdir 22/22 vs GNU coreutils 9.4. - ctest: mkdir+chmod 40/40 in Debug (build-vs-dbg) and Release; cargo test 271 Debug / 251 Release green.
This was referenced Nov 11, 2026
Merged
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.
Fixes the main-branch CI red introduced by the wiring wave (#1561): the three failing mkdir ctests (mkdir_mode_readonly_sets_windows_attribute / mkdir_parents_mode_applies_to_leaf_only / mkdir_mode_1330_symbolic).
Root cause
The wiring routed
mkdir -mthroughmodemap::apply_mode— the chmod-flavored entry whose contract deliberately skips directories ("Windows ignores read-only on dirs"), so FILE_ATTRIBUTE_READONLY never landed on created directories (the pre-wiring C++ pilot did apply it). Same commit exposed a real shared-evaluator bug: an omitted-who=kept umask bits, while GNU modechange.c:340 ('='branch:preserved = (affected ? ~affected : 0) | omit_change) clears them — oracle-verifiedmkdir -m =r→ 400 (old code: 477).Fix
modemap::apply_mode_dir: owner-write → READONLY lands on directories too; the chmodapply_modecontract is unchanged.=semantics fixed in the shared evaluator (umask-0 behavior unchanged).mode_adjust(S_IRWXUGO, true, umask_value, ...)+ gnulib mkdir-p.c:88 explicit chmod of the leaf dir; WSL oracle (umask 077) probes:-m 644→644,=r→400,=w→200,-p -m 555→parent 700/leaf 555.Verification
cargo test 271/271 (Debug) / 251/251 (Release, +4 new umask-window regressions incl. CRT
_umask(077)proving numeric -m bypasses umask); differential gate mkdir 22/22 vs GNU 9.4; ctest mkdir+chmod 40/40 on both Debug and Release builds. The other 13 local Release failures are the known env-noise family (niubash install PATH shadowing, nohup/tty) — CI-irrelevant.