Repository navigation
fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980) - #1992
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the silent cwd pollution in #1980:
cp --parentswith 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
--parentsintermediate loop insrc/commands/cp.cppwalked 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 bareC:folds to the relative nameC<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'smake_dir_parents_privatecreates 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_dirpins the reporter's 4-case repro verbatim (backslash drive-absolute dest with/without trailing backslash, forward-slash control, no--parentscontrol) plus a$TEMP-derived destination case; each asserts the copy, rc 0, and that the cwd listing is unchanged.Verification status
Refs #1980 (not Fixes).