Skip to content

fix(du): follow directory-symlink operands under -L/-H (Refs #1656) - #1663

Closed
caomengxuan666 wants to merge 1 commit into
mainfrom
fix/1656-du-dereference-dirlink
Closed

caomengxuan666 wants to merge 1 commit into
mainfrom
fix/1656-du-dereference-dirlink

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(du): follow directory-symlink operands under -L/-H (Refs #1656)

Summary

du -L -s dirlink(dirlink → dir)报 du: cannot access 'dirlink'、rc=1;
GNU 9.4 跟随链接并打印分配行、rc=0。根因是 -L/-H 门谓词
(du.cpp:1548)用的 std::filesystem::status() 对目录符号链接操作数
报错,活链接被误判为悬空。改用 native_path::attributes_w
(GetFileAttributesW 跟随链接;ls 已因 #1145 走同一原语)。

“错误行缺原因”不是独立格式缺陷:悬空链接的报错按 GNU 本来就没有原因
后缀(本地 9.4 实测 du: cannot access 'dangling');活链接修好后不再
报错,该症状随之消失。悬空臂与缺失臂文本原样保留。

GNU semantics

本地 coreutils 9.4 实测:du -L -s dirlink → 4<TAB>dirlink rc 0;
du -L -s dangling → du: cannot access 'dangling' rc 1;
du -L -s missing → du: cannot access 'missing': No such file or directory rc 1;du -H -s dirlink → 跟随 rc 0。

Verification

  • 回归钉 5 个(tests/unit/du/du_unit_test.cpp):-L/-H 目录链接操作数、
    文件链接锁、悬空精确无原因形、缺失带原因形。
  • fail-first 与 Windows 腿(X299/CI)由复核轮补跑:本机 Linux VM 无法
    编译 Windows-only C++。
  • 无新增用户可见文本,无 I18N 影响。

What this PR deletes

  • 未删产品代码路径。只替换 -L/-H 门的探针原语;悬空/缺失两臂与遍历逻辑不动。

Refs #1656

The -L/-H operand gate probed with std::filesystem::status(), which
reports an error for a directory-symlink operand even when its target
exists, so a live directory link was misread as dangling: `du: cannot
access 'dirlink'`, rc 1. Probe through native_path::attributes_w
(GetFileAttributesW follows the link; ls already routes its operand
probes through the same helper, #1145). The dangling-vs-missing
distinction is unchanged: a dangling link still prints no errno text,
exactly like GNU coreutils 9.4 (probed).

Tests: 5 new cases in tests/unit/du/du_unit_test.cpp (-L/-H dirlink
operands, file-link lock, dangling exact no-reason form, missing
reason form).
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核:FAIL(自家新钉在 CI 红)

build-windows x64 default 红,3882 测中仅 2 败,皆为本 PR 新钉(并行跑 + ctest-gate 串行重试皆红,非 flake;队长读过失败日志原文):

Windows 上 du -L dangling 实测 rc 0、stderr 空,而 GNU 为 rc 1 + du: cannot access 'dangling'(无原因;缺失形带 : No such file or directory)。跟随一半是对的(其余 du 测全绿),缺的是不可解析操作数的报错臂。

返工:给 dangling 操作数补报错臂(rc 1 + du: cannot access '<name>',无原因后缀),与 GNU 两种形态(dangling 无原因 / 缺失带 : No such file or directory)对齐;重跑 CI。

@caomengxuan666

Copy link
Copy Markdown
Member Author

Superseded: #1656 fix merged via #1695.

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