You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cp --parents with a backslash drive-absolute destination leaves a C: directory in the current directory #1980
s=$(mktemp -d)||exit 1
mkdir -p "$s/w/src/a""$s/d"&&echo x >"$s/w/src/a/f"&&echo y >"$s/w/g"cd"$s/w"||exit 1
D=$(cygpath -w "$s/d")
cp --parents g "$D\\";echo"1 flat file, D\\: rc=$? cwd: $(ls -A | tr '\n''')"; rm -rf ./C*
cp --parents src/a/f "$D";echo"2 nested, D: rc=$? cwd: $(ls -A | tr '\n''')"; rm -rf ./C*
cp --parents g "$(cygpath -m "$s/d")/";echo"3 forward slashes: rc=$? cwd: $(ls -A | tr '\n''')"
cp g "$D\\";echo"4 no --parents: rc=$? cwd: $(ls -A | tr '\n''')"echo"dest: $(cd "$s/d"&& find . -type f | sort | tr '\n''')"cd / && rm -rf "$s"
Run in Git Bash, with WinuxCmd's cp.exe first on PATH.
WinuxCmd main:
1 flat file, D\: rc=0 cwd: C: g src
2 nested, D: rc=0 cwd: C: g src
3 forward slashes: rc=0 cwd: g src
4 no --parents: rc=0 cwd: g src
dest: ./g ./src/a/f
GNU coreutils 8.32 (Git for Windows), and WinuxCmd 1.2.3 (WinuxCmd-1.2.3-win-x64.tar.gz):
1 flat file, D\: rc=0 cwd: g src
2 nested, D: rc=0 cwd: g src
3 forward slashes: rc=0 cwd: g src
4 no --parents: rc=0 cwd: g src
dest: ./g ./src/a/f
When the destination is a drive-absolute path written with backslashes (C:\…\d or C:\…\d\), every cp --parents leaves an empty directory named C + U+F03A (shown as C:) in the current directory. This happens even when no intermediate directory has to be created (case 1). The copy itself is correct and the exit status is 0, so nothing reports it. A destination with forward slashes (case 3) and cp without --parents (case 4) are not affected. In niubash, cp --parents … "$TEMP/x/" hits this because $TEMP is C:\Users\…\Temp.
Possibly related: the intermediate-directory loop after parents_graft_path in src/commands/cp.cpp calls create_directory_recursive on each \-separated prefix of the whole destination path, so the first prefix is the bare C:. The output first changes at 7f576d1 (#1874): its parent 32406e3 prints the GNU output for cases 1 and 2, and 7f576d1 prints C:. That commit makes the path fold treat a bare C: as a relative colon name, so the create now lands in the current directory. GNU cp.c make_dir_parents_private only creates the directories below the destination.
WinuxCmd main at a5eed6f, 7f576d1 and 32406e3 (each built with scripts/build-with-vs.ps1, Release), WinuxCmd 1.2.3 release; Git Bash 5.3.15; Windows 11.
The issue was drafted with Claude and the reproductions were run on the versions above.
Confirmed. This is real, and it is a regression on main: 1.2.3 is clean,
main at a5eed6fb is not. Thank you for the version-pinned repro and the
bisection — both check out.
What I verified:
GNU side (pristine coreutils 9.4 oracle, cp (GNU coreutils) 9.4): cp --parents src/a/f d and cp --parents g d/ leave the cwd untouched
and put the files under d/. With the backslash spelling cp --parents g 'C:\tmp\xyz\d\' GNU refuses (with --parents, the destination must be a directory, rc 1) and creates nothing in the cwd —
it never splits on \ and never creates anything outside the destination
subtree. make_dir_parents_private only creates below the destination.
Mechanism (source, at your tested ref a5eed6fb): the live cp on main
is the C++ implementation (the Rust wire was rolled back by fix(cp): restore the C++ product path until the Rust wire passes symlink recreation (#1757) #1795, cp is
not in WINUXCMD_RUST2_COMMANDS). The --parents loop at src/commands/cp.cpp:2262-2270 walks every \ prefix of the whole
destination path and creates each one except the full dest itself — so for
a backslash drive-absolute dest the first prefix created is the bare C:.
And since 7f576d1d ([bug] applets fail on literal-colon operands: canon layer does not carrier-encode operand path components #1874) a bare C: is no longer drive syntax in the
path fold: it folds to the relative name C + U+F03A and lands in the cwd.
Your bisection is exactly right — the commit changed only the two fold
twins, and before it a bare D: was explicitly exempted as "the drive
itself, not a file name". This also explains your controls: forward-slash
dests (case 3) have no \ for the loop to split on, and no --parents
(case 4) never enters the loop.
Why it matters beyond the repro: any backslash drive-absolute --parents destination triggers it, including $TEMP-derived paths
(C:\Users\…\Temp), and it fires even when no intermediate directory
needs creating. The copy itself is correct and rc stays 0, so nothing
reports it.
Severity: P2-medium — silent cwd pollution on a common spelling, no data
loss, no wrong copy, not yet shipped (1.2.3 clean). Suggested labels: bug + compat-verified.
Fix direction for whoever picks this up: the loop should only create prefixes
strictly below the destination (GNU creates only below the destination), not
every \ prefix of the whole path — the partial != destPath guard is the
wrong shape. The #1874 fold itself should not be reverted: the
bare-D:-is-a-relative-name contract is deliberate (shell/MSYS side) and
other applets depend on it. The Rust port's make_parents does not share
this face (it only creates graft prefixes under the target), but it is not
the live implementation right now.
PR #1992 merged (merge commit 646d4e8e). The fix is one change in the --parents intermediate-directory loop (src/commands/cp.cpp): the scan now starts at destPath.size() instead of 0, so it only creates prefixes strictly below the destination — 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. The #1874 fold is untouched, as is the Rust make_parents (not the live implementation).
Verification: CI full green on the PR head, CTest 4082/4082 (baseline 4081 + the new pin). The new pin cp_parents_backslash_drive_dest_leaves_no_drive_dir is your 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.
One honest shortfall, recorded in the lane dossier: the fail-first re-run on a real Windows host could not be done this round — the devin-windows, devin-ubuntu and X299 tunnels were all down, and the lane does not build locally or under Wine. The evidence for the fix is the exact code path (old code called create_directory_recursive("C:") for your cases 1/2, matching your bisection to #1874) plus the CI pin passing on the fixed code. The re-run of your 4-case script on devin-windows is owed once the tunnel recovers; I will do it then and report back here if it disagrees.
Closing as fixed — thank you again for the version-pinned repro and the bisection, both of which checked out exactly.
Activity
caomengxuan666 commentedon Nov 30, 2026
Triage — confirmed, P2-medium regression on main
Confirmed. This is real, and it is a regression on main: 1.2.3 is clean,
main at
a5eed6fbis not. Thank you for the version-pinned repro and thebisection — both check out.
What I verified:
cp (GNU coreutils) 9.4):cp --parents src/a/f dandcp --parents g d/leave the cwd untouchedand put the files under
d/. With the backslash spellingcp --parents g 'C:\tmp\xyz\d\'GNU refuses (with --parents, the destination must be a directory, rc 1) and creates nothing in the cwd —it never splits on
\and never creates anything outside the destinationsubtree.
make_dir_parents_privateonly creates below the destination.a5eed6fb): the livecpon mainis the C++ implementation (the Rust wire was rolled back by fix(cp): restore the C++ product path until the Rust wire passes symlink recreation (#1757) #1795,
cpisnot in
WINUXCMD_RUST2_COMMANDS). The--parentsloop atsrc/commands/cp.cpp:2262-2270walks every\prefix of the wholedestination path and creates each one except the full dest itself — so for
a backslash drive-absolute dest the first prefix created is the bare
C:.And since
7f576d1d([bug] applets fail on literal-colon operands: canon layer does not carrier-encode operand path components #1874) a bareC:is no longer drive syntax in thepath fold: it folds to the relative name
C+ U+F03A and lands in the cwd.Your bisection is exactly right — the commit changed only the two fold
twins, and before it a bare
D:was explicitly exempted as "the driveitself, not a file name". This also explains your controls: forward-slash
dests (case 3) have no
\for the loop to split on, and no--parents(case 4) never enters the loop.
--parentsdestination triggers it, including$TEMP-derived paths(
C:\Users\…\Temp), and it fires even when no intermediate directoryneeds creating. The copy itself is correct and rc stays 0, so nothing
reports it.
Severity: P2-medium — silent cwd pollution on a common spelling, no data
loss, no wrong copy, not yet shipped (1.2.3 clean). Suggested labels:
bug+compat-verified.Fix direction for whoever picks this up: the loop should only create prefixes
strictly below the destination (GNU creates only below the destination), not
every
\prefix of the whole path — thepartial != destPathguard is thewrong shape. The #1874 fold itself should not be reverted: the
bare-
D:-is-a-relative-name contract is deliberate (shell/MSYS side) andother applets depend on it. The Rust port's
make_parentsdoes not sharethis face (it only creates graft prefixes under the target), but it is not
the live implementation right now.
Dossier:
lane-1980-triage-2026-11-30.md.Merge pull request #1992 from unixwin/captain/1980-cp-parents-drive
caomengxuan666 commentedon Nov 30, 2026
Fixed and merged — #1992
PR #1992 merged (merge commit
646d4e8e). The fix is one change in the--parentsintermediate-directory loop (src/commands/cp.cpp): the scan now starts atdestPath.size()instead of0, so it only creates prefixes strictly below the destination — GNU'smake_dir_parents_privatecreates only below the destination, and the destination itself is required to exist (--parents, #1066), so none of its prefixes ever needs creating. The #1874 fold is untouched, as is the Rustmake_parents(not the live implementation).Verification: CI full green on the PR head, CTest 4082/4082 (baseline 4081 + the new pin). The new pin
cp_parents_backslash_drive_dest_leaves_no_drive_diris your 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.One honest shortfall, recorded in the lane dossier: the fail-first re-run on a real Windows host could not be done this round — the devin-windows, devin-ubuntu and X299 tunnels were all down, and the lane does not build locally or under Wine. The evidence for the fix is the exact code path (old code called
create_directory_recursive("C:")for your cases 1/2, matching your bisection to #1874) plus the CI pin passing on the fixed code. The re-run of your 4-case script on devin-windows is owed once the tunnel recovers; I will do it then and report back here if it disagrees.Closing as fixed — thank you again for the version-pinned repro and the bisection, both of which checked out exactly.
rust2(port+wire): cat -> rust2 library + bridge (#1488) (#1882)
rust2(port+wire): uniq -> rust2 library + bridge (#1488) (#1877)