Skip to content

fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980) - #1992

Merged
caomengxuan666 merged 2 commits into
mainfrom
captain/1980-cp-parents-drive
Nov 30, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
captain/1980-cp-parents-drive

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fixes the silent cwd pollution in #1980: cp --parents with a backslash drive-absolute destination created the bare drive designator (C:) as a directory in the cwd.

UNVERIFIED-BY-CAPTAIN — captain verification pending (see below).

Root cause

The --parents intermediate loop in src/commands/cp.cpp walked every \ prefix of the whole destination path, so for a backslash drive-absolute destination the first prefix created was the bare drive designator (C:). Since #1874 a bare C: folds to the relative name C<U+F03A> and landed as a stray directory in the cwd — silent (copy correct, rc 0), firing even when no intermediate directory needed creating, including $TEMP-derived destinations.

Fix

Start the scan at destPath.size() so only prefixes strictly below the destination are created (GNU's make_dir_parents_private creates only below the destination). The destination itself is required to exist (--parents, #1066), so none of its prefixes ever needs creating here. The #1874 fold itself is untouched.

Tests

New cp_parents_backslash_drive_dest_leaves_no_drive_dir pins the reporter's 4-case repro verbatim (backslash drive-absolute dest with/without trailing backslash, forward-slash control, no --parents control) plus a $TEMP-derived destination case; each asserts the copy, rc 0, and that the cwd listing is unchanged.

Verification status

  • Not yet run on a Windows host: the devin-windows and X299 tunnels were both down when this PR was opened, so the regression test has not been executed against a built binary. CI (Windows build legs) is the first verification; a real-machine re-run of the reporter's 4-case script is owed once the devin-windows tunnel recovers.
  • The fix is a one-line scan-start change plus comment; the graft-intermediate creation below the destination is unchanged.

Refs #1980 (not Fixes).

… cwd (Refs #1980)

Refs #1980 (not Fixes).

The --parents intermediate loop walked every '\\' prefix of the
whole destination path, so for a backslash drive-absolute
destination the first prefix created was the bare drive designator
("C:"). Since #1874 a bare "C:" folds to the relative name
"C<U+F03A>" and landed as a stray directory in the cwd — silent
(copy correct, rc 0), and it fired even when no intermediate
directory needed creating, including $TEMP-derived destinations.
GNU's make_dir_parents_private creates only below the destination,
and the destination itself is required to exist (--parents, #1066),
so none of its prefixes ever needs creating here: start the scan
at destPath.size(). The #1874 fold itself is untouched (the
bare-"D:"-is-a-relative-name contract is deliberate).

Pin: cp_parents_backslash_drive_dest_leaves_no_drive_dir — the
reporter's 4-case repro verbatim (backslash drive-absolute dest
with/without trailing backslash, forward-slash control, no
--parents control) plus a $TEMP-derived destination case; each
asserts the copy, rc 0, and that the cwd listing is unchanged.
The five cwd-listing assertions used EXPECT_EQ on two
std::set<std::string> values; wctest::expect_eq_impl only
accepts strings (C2664 on the x64 default leg). Switch them to
EXPECT_TRUE(set == set). No production code touched.
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