Skip to content

[cp] -i 拒绝复制时退出码为 0(GNU 为 1) #1648

Closed

Description

@caomengxuan666

现象

cp -i a b 回答 n(或 stdin EOF)时,GNU 不复制且 rc=1;WinuxCmd 不复制但 rc=0。提示与文件状态一致,仅退出码不同。mv -i/rm -i 在 WinuxCmd 已正确返回 1。

  • WinuxCmd:WinuxCmd 1.2.1(基线 b781ff3,Release 构建)

  • GNU oracle:coreutils 9.4(WSL2),LC_ALL=C、TZ=UTC

  • 契约锚点:DOCS/oracle-audit/cp.md 行 C03 / C05

复现

$d = "$env:TEMP\cp-i"; Remove-Item -Recurse -Force $d -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Force -Path $d | Out-Null
"A" | Set-Content "$d\a.txt"; "B" | Set-Content "$d\b.txt"
"n" | & "...\cp.exe" -i "$d\a.txt" "$d\b.txt" ; "rc=$LASTEXITCODE"
Get-Content "$d\b.txt"

GNU 9.4(expected):cp: overwrite 'b.txt'? ,rc=1,b.txt=B。

WinuxCmd 1.2.1(actual):cp: overwrite 'b.txt'? ,rc=0,b.txt=B。

影响

交互脚本/set -e 无法用退出码识别“用户拒绝”。

Activity

  1. added
    compat-gap
    on Nov 14, 2026
  2. caomengxuan666 commented on Nov 14, 2026

    @caomengxuan666
    MemberAuthor

    intake 定序:cp 面同文件串行——本单待 #1647 合入后派修(队长队列,先派 #1647)。

  3. caomengxuan666 commented on Nov 14, 2026

    @caomengxuan666
    MemberAuthor

    接管复核(基线 8be156e3,工作区 wc-cpfix)

    已修复,根因在 copy_file():-i 拒绝(含 stdin EOF)走了 return true,而 process_source_paths 也只检查 !fileResult(错误分支),从不看返回的 bool,于是 rc=0。

    GNU 9.4 依据 copy.c:2420-2432:I_ASK_USER 分支回答否(yesno() 在 EOF 也为 false)后 skipped = true; return_val = x->interactive == I_ALWAYS_SKIP;——-i 是 I_ASK_USER,故为 false,cp.c 收尾为退出码 1。修复让拒绝返回 false,并在顶层与递归两层把 *fileResult == false 记为失败(不额外打印诊断)。

    字节对照(printf 'n\n' | cp -i a b):

    • 修前:cp: overwrite 'b'? + rc 0
    • 修后:cp: overwrite 'b'? + rc 1(与 GNU 9.4 一致,b 不变)
    • EOF:同 rc 1;回答 y 仍 rc 0 并覆盖。

    新增 4 条测试:cp.issue1648_interactive_decline_exits_one、..._eof_exits_one、..._accept_still_succeeds、..._recursive_interactive_decline_exits_one 全部 PASSED。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

compat-gap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions