Repository navigation
fix(date): read -r/--reference FILE through the shared path boundary - #1263
Conversation
…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.
独立代码评审结论:APPROVEPR #1263( 读取点穷尽(核心) — date.cpp 恰有两个文件读取点: 边界矩阵复验 — PS 原生 argv、 回归 — 3 新例自跑全 PASSED(fixture 自盘合成,任意主机可过);ctest 全量 3066/3066 通过,0 失败;夹带扫描:改动恰为 CHANGELOG.md / src/commands/date.cpp / tests/unit/date/date_unit_test.cpp 三文件,无 同族一致性 — 与 #1239 合并预演 — 分支基于当前 origin/main 顶端(merge-base = 23f37f5),单提交,merge 预演 Already up to date,无冲突。 非阻塞备注:① 多盘主机上 不合并,评审 worktree 已删。 |
Closes #1256.
Problem
date -r FILE/--reference=FILEprobed the operand with a rawGetFileAttributesExWcall (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 aforeign cwd
date -rreportedfailed to get modification timefor a filethat exists on the operand's drive, while MSYS
datereads the same spellingfrom anywhere. This is the same family as the
-f DATEFILEopen fixed in#1239 (and #1238's ldd read):
-ris date's second read point in thatfamily, found by the #1230 sweep.
Fix
The operand folds once through the shared
normalize_api_operandboundaryinside
read_reference_time— the single read point that both-r FILEand--reference=FILEfeed. The failure message keeps quoting the operand exactlyas typed, like MSYS does.
Verification (per #1230: PS/cmd native argv probes)
E-drive probe:
E:\probe\ref1256.txt,LastWriteTimeUtcstamped to2024-01-02 03:04:05; binaryD:\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.
/e/probe/ref1256.txtC:\2024-01-02T03:04:052024-01-02T03:04:052024-01-02T03:04:052024-01-02T03:04:05/e/probe/ref1256.txtD:\2024-01-02T03:04:052024-01-02T03:04:052024-01-02T03:04:052024-01-02T03:04:05/cygdrive/e/probe/ref1256.txtC:\2024-01-02T03:04:05/cygdrive/e/probe/ref1256.txtD:\2024-01-02T03:04:05/mnt/e/probe/ref1256.txtC:\2024-01-02T03:04:05/mnt/e/probe/ref1256.txtD:\2024-01-02T03:04:05Pre-fix check: with only
read_reference_timereverted, the newdate_reference_drive_dialect_*ctest cases fail (red/green verified in thisworktree); with the fix they pass.
Shadow witness (
Test-Pathbefore / after / after cleanup):C:\e=False,C:\d=False,D:\e=Falsethroughout.E:\probecreated for the audit andremoved afterwards.
Tests
date_reference_drive_dialect_spellings_read_from_foreign_cwd— slash,/cygdriveand/mntspellings of a TempDir-fixture file (drive lettersynthesized 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:05from a foreign cwd.date_reference_drive_dialect_cwd_on_other_drive_reads_file— the audit'sexact 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 missingreference still fails with exit 1 and the operand quoted as typed.
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.