Skip to content

fix(mkdir): wire -m through a directory-applying mode path; fix omitted-who '=' umask leak (main CI red) - #1564

Merged
caomengxuan666 merged 1 commit into
mainfrom
rust2/wire-wave1
Nov 11, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
rust2/wire-wave1

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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 -m through modemap::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-verified mkdir -m =r → 400 (old code: 477).

Fix

  • modemap::apply_mode_dir: owner-write → READONLY lands on directories too; the chmod apply_mode contract is unchanged.
  • omitted-who = semantics fixed in the shared evaluator (umask-0 behavior unchanged).
  • GNU evidence: coreutils src/mkdir.c main() 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.

…#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.
@caomengxuan666
caomengxuan666 merged commit 438a766 into main Nov 11, 2026
10 checks passed
@caomengxuan666
caomengxuan666 deleted the rust2/wire-wave1 branch November 18, 2026 05:50
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.

1 participant