Skip to content

fix(date): read -r/--reference FILE through the shared path boundary - #1263

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1256-date-reference
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1256-date-reference

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1256.

Problem

date -r FILE / --reference=FILE probed the operand with a raw
GetFileAttributesExW call (read_reference_time, src/commands/date.cpp:1208).
A POSIX drive-dialect spelling — /e/Data/ref, /cygdrive/e/Data/ref,
/mnt/e/Data/ref — was rooted on the current drive by Win32, so from a
foreign cwd date -r reported failed to get modification time for a file
that exists on the operand's drive, while MSYS date reads the same spelling
from anywhere. This is the same family as the -f DATEFILE open fixed in
#1239 (and #1238's ldd read): -r is date's second read point in that
family, found by the #1230 sweep.

Fix

The operand folds once through the shared normalize_api_operand boundary
inside read_reference_time — the single read point that both -r FILE and
--reference=FILE feed. The failure message keeps quoting the operand exactly
as typed, like MSYS does.

Verification (per #1230: PS/cmd native argv probes)

E-drive probe: E:\probe\ref1256.txt, LastWriteTimeUtc stamped to
2024-01-02 03:04:05; binary D:\repo\winuxcmd-wt-1256\build-vs\usr\bin\date.exe
(this branch, scripts/build.py); oracle MSYS D:\Git\usr\bin\date.exe +
PowerShell third party.

operand cwd probe (PS argv) probe (cmd argv) MSYS oracle PS oracle result
/e/probe/ref1256.txt C:\ exit 0, 2024-01-02T03:04:05 exit 0, 2024-01-02T03:04:05 2024-01-02T03:04:05 2024-01-02T03:04:05 MATCH
/e/probe/ref1256.txt D:\ exit 0, 2024-01-02T03:04:05 exit 0, 2024-01-02T03:04:05 2024-01-02T03:04:05 2024-01-02T03:04:05 MATCH
/cygdrive/e/probe/ref1256.txt C:\ exit 0, 2024-01-02T03:04:05 — (MSYS does not accept the spelling) — correct (WinuxCmd dialect contract)
/cygdrive/e/probe/ref1256.txt D:\ exit 0, 2024-01-02T03:04:05 — (same) — correct
/mnt/e/probe/ref1256.txt C:\ exit 0, 2024-01-02T03:04:05 — (same) — correct
/mnt/e/probe/ref1256.txt D:\ exit 0, 2024-01-02T03:04:05 — (same) — correct

Pre-fix check: with only read_reference_time reverted, the new
date_reference_drive_dialect_* ctest cases fail (red/green verified in this
worktree); with the fix they pass.

Shadow witness (Test-Path before / after / after cleanup): C:\e=False,
C:\d=False, D:\e=False throughout. E:\probe created for the audit and
removed afterwards.

Tests

  • date_reference_drive_dialect_spellings_read_from_foreign_cwd — slash,
    /cygdrive and /mnt spellings of a TempDir-fixture file (drive letter
    synthesized from the fixture itself, so any host passes — fix(ldd,date): fold POSIX drive-dialect operands before any open (#1238 #1239) #1253 precedent)
    read the stamped mtime 2024-01-02T03:04:05 from a foreign cwd.
  • date_reference_drive_dialect_cwd_on_other_drive_reads_file — the audit's
    exact shape: cwd at the root of a second fixed drive, operand spelled for the
    fixture's drive (skips when no second fixed drive exists).
  • date_reference_missing_dialect_operand_quotes_as_typed — a missing
    reference still fails with exit 1 and the operand quoted as typed.
  • Full ctest suite: 3066/3066 passed (build via scripts/build.py).

I18N

No new user-visible strings: the `failed to get modification time of '...'
message already existed and is unchanged; only the path handed to Win32 is
folded. No catalog change required.

…1256)

date -r/--reference probed the operand with a raw GetFileAttributesExW
call, so a POSIX drive-dialect spelling ('/e/Data/ref', '/cygdrive/e/...',
'/mnt/e/...') was rooted on the CURRENT drive - from a foreign cwd -r
reported "failed to get modification time" for a file that exists on the
operand's drive, while MSYS date reads the same spelling from anywhere
(found by the #1230 sweep; PS/cmd probe with native argv, MSYS date
oracle, PowerShell LastWriteTimeUtc three-way). This is the same family
the -f DATEFILE open belongs to, fixed in #1239; the -r read point is
date's second one.

The operand folds once through the shared normalize_api_operand boundary
inside read_reference_time (the single read point both -r and
--reference= feed); the failure message keeps quoting the operand
exactly as typed, like MSYS does.

Regressions dialect-spell a TempDir fixture (slash, /cygdrive and /mnt
forms read the stamped mtime from a foreign cwd), repeat the audit's
exact shape with the cwd on a second fixed drive, and pin that a missing
reference still fails with the operand quoted as typed.
@caomengxuan666

Copy link
Copy Markdown
Member Author

独立代码评审结论:APPROVE

PR #1263(fix/1256-date-reference,431931c)由独立评审代理在自建 worktree 上完成全量复验,逐项如下。

读取点穷尽(核心) — date.cpp 恰有两个文件读取点:read_reference_time(GetFileAttributesExW,本 PR 折叠)与 -f DATEFILE 的 is_directory/ifstream(#1239 已折叠)。--reference= 与 -r 在 operand 收集处汇入唯一 reference_path,唯一消费点是 2293 行的单次 read_reference_time 调用;除 1220 行外全文件再无 GetFileAttributesExW/CreateFile/stat/ifstream 消费该操作数。折叠一折全包,无遗漏。错误消息打印原始 reference_path(用户拼写),与 MSYS 一致。

边界矩阵复验 — PS 原生 argv、E:\probe-cr1263 自建自清:3 拼写(/e/…、/cygdrive/e/…、/mnt/e/…)× 2 形(-r、--reference=)× 2 外乡 cwd(D:\、C:\)共 12 项,全部与 PS LastWriteTimeUtc oracle(定戳 2024-01-02T03:04:05Z)MATCH,exit 0、stderr 空。裸 /e(目录)双 cwd 均返回 E:\ 目录 mtime,与 PS oracle 一致(同 GNU stat 目录语义)。缺失文件 4 项 exit 1 且操作数按原拼写引用。Windows 拼写基线不受影响。影子扫描 C:\e、C:\d、D:\e、C:\mnt、C:\cygdrive 等全 False。备注:本评审主机无 MSYS2/Cygwin,MSYS oracle 无法本地复现,以 PS oracle + 定戳比对替代(记录项,不阻塞)。

回归 — 3 新例自跑全 PASSED(fixture 自盘合成,任意主机可过);ctest 全量 3066/3066 通过,0 失败;夹带扫描:改动恰为 CHANGELOG.md / src/commands/date.cpp / tests/unit/date/date_unit_test.cpp 三文件,无 link 复辟、无夹带;红绿验证:回退折叠单点重编译后两个方言读取回归转红(缺失文件例按设计保持绿——消息引用与折叠无关),恢复后 4/4 绿。

同族一致性 — 与 #1239 -f 折叠完全同款:读点内、Win32 调用前折一次 normalize_api_operand,消息保原文拼写;date_dialect_detail 助手(#1239 引入、经 #1253 合入 main)原样复用,测试三例与 -f 同构。

合并预演 — 分支基于当前 origin/main 顶端(merge-base = 23f37f5),单提交,merge 预演 Already up to date,无冲突。

非阻塞备注:① 多盘主机上 other_fixed_drive cwd 测试有跳过守卫,单盘主机自跳过,与 #1239 一致,可接受;② MSYS oracle 本机不可复现如上。

不合并,评审 worktree 已删。

@caomengxuan666
caomengxuan666 merged commit 73f6126 into main Oct 19, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1256-date-reference branch October 21, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant