Skip to content

cp: -n is I_ALWAYS_NO per pristine GNU 9.4 (#1879) - #1978

Merged
caomengxuan666 merged 2 commits into
mainfrom
captain/1879-cp-n-always-no
Nov 29, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
captain/1879-cp-n-always-no

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #1879

UNVERIFIED-BY-CAPTAIN — lane delivery, code only. Captain to verify via CI
(full rust tests + CTest) before merge.

What

cp -n now follows pristine GNU coreutils 9.4 instead of the Ubuntu
9.4-3ubuntu6.2 build's patched behavior (the port's original oracle):

  • -n maps to I_ALWAYS_NO (cp.c:1070), not the silent I_ALWAYS_SKIP.
    An existing destination is reported and fails the file:
    cp: not replacing '<dst>', rc 1 (copy.c:2438). A fresh copy under -n
    prints nothing. --update=none keeps the silent-skip form, rc 0.
  • The Ubuntu-only deprecation warning
    (warning: behavior of -n is non-portable..., absent from the pristine
    9.4 tree) is no longer printed.
  • -n combined with backups is the cp.c:1220 usage error
    options --backup and --no-clobber are mutually exclusive — for
    -b/--backup with any control (including --backup=none) and for
    -S/--suffix (both set make_backups, cp.c:1027/1191), whether or
    not a destination exists yet.
  • While -n is active, an explicit --update=WHEN is not argmatched
    (cp.c:1136), so -n --update=all no longer restores copying; -i/-n
    last-wins is unchanged (-ni prompts, -in reports not replacing).

The mv port already implements exactly this state machine; this change
brings cp onto the same single mechanism (including the
command.*.error.not_replacing / ...backup_and_no_clobber key shapes).

Oracle evidence (pristine coreutils 9.4 tarball build, cloud oracle):
cp -n a keep → not replacing 'keep', rc 1; cp -n a fresh → silent,
rc 0; dir-target skip reports the joined path; -n a a → not replacing;
-n -b, -nb, -n --backup=none, -n -S .bak → mutual-exclusion usage
error; --update=none faces all silent rc 0.

What this PR deletes

  • The deprecation-warning print block in cp_cmd.
  • The no_clobber_seen option field and all its assignments (its only
    reader was the warning).
  • The .deb-behavior assertions in three tests (rewritten to pristine
    behavior, see below). No second mechanism is introduced: -n and
    --update=none stop sharing one silent branch and take GNU's two
    existing states.

Tests

Rewritten: no_clobber_skip_reports_not_replacing,
interactive_and_no_clobber_are_last_wins,
no_clobber_skips_existing_and_copies_new,
update_all_after_no_clobber_does_not_restore_copying.
New: update_none_skips_silently,
no_clobber_same_file_reports_not_replacing,
no_clobber_and_backup_are_mutually_exclusive,
no_clobber_skip_inside_directory_target_reports_joined_path.

Net lines

Production +67/−39 (net +28); tests +100/−21 (net +79).

i18n (companion, captain-side)

  • New keys (English fallback in tr!): command.cp.error.not_replacing,
    command.cp.error.backup_and_no_clobber — winuxcmd-i18n sync PR needs
    the zh entries + VERSION bump.
  • command.cp.warning.no_clobber_deprecated is now unreferenced —
    orphan-key deletion PR in winuxcmd-i18n (not --update-baseline).
  • zh text of command.cp.option.no-clobber ("…也不报错") should be
    adjusted in the sync PR; -n does report now.

Deliberately unchanged

-S alone still creates no backup (the port's documented divergence
from the tarball, where make_backups also drives backup_type);
here make_backups is tracked only for the cp.c:1220 conflict check.

-n mapped to Interactive::AlwaysNo (cp.c:1070) instead of the Ubuntu
.deb's silent AlwaysSkip: an existing destination now reports
'not replacing <dst>' and fails the file (copy.c:2438), a fresh copy
under -n prints nothing, and the .deb-only deprecation warning is
gone (no_clobber_seen deleted; make_backups added for the cp.c:1220
--backup/--no-clobber mutual exclusion, set by -b/--backup and
-S/--suffix per cp.c:1027/1191). --update=none keeps the silent
AlwaysSkip form. New i18n keys: command.cp.error.not_replacing,
command.cp.error.backup_and_no_clobber (mv precedent).

Refs #1879 (not Fixes).
… .deb

The three -n-final rows were calibrated against the WSL distro's
Ubuntu .deb cp 9.4, whose -n is patched to a silent rc-0 skip. The
pristine coreutils 9.4 tarball oracle (this project's standard)
prints "cp: not replacing '<dst>'" and exits 1 for exactly these
combinations (-n, -nv, -nv --update=all, -v -i -n), matching the
port after this PR. The rows stay as record-only (note) so both
sides keep being measured without gating on the .deb divergence.
@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN adjudication of the CI reds on this PR (2026-11-30):

i18n-drift — expected red until winuxcmd-i18n #43 (the two new cp keys) merged; it has now merged, so this job should go green on the next run.

rust2-gate, cp32 / cp34 / cp39 (3 FAIL rows) — not a port regression; a gate-calibration defect. All three rows are the combinations where -n is the final effective mode against an existing destination. The gate's GNU side is the WSL distro's Ubuntu .deb cp 9.4, whose -n is distro-patched to a silent rc-0 skip. The pristine coreutils 9.4 tarball oracle — this project's only accepted oracle — says otherwise, re-verified by the captain today on the cloud oracle binary:

  • cp -n a b → cp: not replacing 'b', rc 1
  • cp -nv a b → same, rc 1
  • cp -nv --update=all a b → same, rc 1
  • cp -v -i -n a b (answer y) → same, rc 1 (the -n wins; no prompt)
  • control cp -n -i a b (answer y) → prompts, copies, rc 0 — matches gate row cp33, which passes

The port after this PR matches the pristine oracle on every row. I have set cp32/cp34/cp39 to note (record-only, the gate's documented-deviation mode) in a captain fixup commit on this branch, with the reason recorded in the commit message: the rows keep measuring both sides but no longer gate on the .deb divergence. This is the same trap that masked the original cp -n divergence on 2026-11-25 (.deb oracle); the table had inherited the .deb calibration.

@caomengxuan666
caomengxuan666 merged commit 9079670 into main Nov 29, 2026
57 of 60 checks passed
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