Skip to content

[gap] cp -r dereferences in-tree symlinks/junctions (copies target contents), fails on dangling links, cyclic junction explodes ~31 levels #1064

Closed

Description

@caomengxuan666

Summary

cp -r dereferences symlinks/junctions it encounters during recursive traversal (copying the target's contents as a real directory) instead of copying them as links — and a cyclic link explodes ~31 levels deep until the path-length limit stops it. A dangling symlink in the tree makes the whole copy fail. GNU cp -r preserves symlinks as symlinks (verified on real GNU 9.4 via WSL; also reproduces under MSYS 8.32 with MSYS=winsymlinks).

Repro

mkdir -p wA/sub && echo f > wA/sub/f.txt
MSYS=winsymlinks:nativestrict ln -s sub wA/slink
MSYS=winsymlinks:nativestrict ln -s nonexistent wA/dangling
winuxcmd.exe cp -r wA B3
  ->  cp: error copying directory 'wA'   rc=1
      B3/slink is a REAL DIR containing f.txt (link dereferenced)
      B3/dangling MISSING (copy of the dangling link failed -> whole tree errors)

GNU 9.4 (WSL): cp -r wA wB -> rc=0
      wB/slink -> sub            (link preserved)
      wB/dangling -> nonexistent (dangling link preserved)

Cyclic link blowup

mkdir A && cmd /c "mklink /J A\back A"     :: junction A\back -> A
echo x > A\file.txt
winuxcmd.exe cp -r A B2                    -> rc=0, creates B2\back\back\back\... 31 levels deep
                                              (65 objects; bounded only by MAX_PATH)
GNU:                                        creates the link once, no recursion (5 objects total)

Note ls -R, du, rm -r, chmod -R correctly do NOT traverse these links — only cp -r does. rm -r on the result correctly removed the junction without touching the target.

Versions

  • WinuxCmd 1.0.6 (build-vs, WINUX_LANG=en)
  • GNU coreutils 9.4 (WSL, authoritative) / 8.32 (MSYS)

Activity

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

    @caomengxuan666
    MemberAuthor

    Fixed/verified in 38c8461 / fffd886 / da0e9e8 — GNU-compatible semantics verified against WSL coreutils 9.4; see issues/report-misc.md, report-dd.md, report-cp-mv-install.md.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompat-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions