cp --no-dereference --preserve=links copies directory symlinks as file symlinks

Open
#106 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust

Research direction

Reproduce the Windows commands in the issue and start at the cp implementation, focusing on how directory symlinks are classified and recreated with --no-dereference. Done means copying the sample preserves aaa2 as a directory symlink that supports listing and chdir, while regular file symlink behavior remains unchanged.

Written by the indexing model from the issue text.

Description

C-bug

cp -a implies --no-dereference --preserve=links

When as an elevated user I archive-copy a directory containing directory symlinks I expect them to be preserved as true directory symlinks but regular file symlinks are created instead in the destination and they're dysfunctional: you cannot list files inside or chdir into them.

>cmd.exe

>"C:\Program Files\coreutils\bin\cp.exe" --version
cp (uutils coreutils) 0.8.0

>mkdir src\aaa1\sub

>mklink /D src\aaa2 aaa1
symbolic link created for src\aaa2 <<===>> aaa1

>dir src
 Directory of L:\BASINPAD\bench\src

09/06/2026  09:32    <DIR>          .
09/06/2026  09:32    <DIR>          ..
09/06/2026  09:32    <DIR>          aaa1
09/06/2026  09:32    <SYMLINKD>     aaa2 [aaa1]
               0 File(s)              0 bytes
               4 Dir(s)  11,395,715,072 bytes free

>"C:\Program Files\coreutils\bin\cp.exe" -av src dst
'src' -> 'dst\'
'src\aaa1' -> 'dst\aaa1'
'src\aaa1\sub' -> 'dst\aaa1\sub'
'src\aaa2' -> 'dst\aaa2'

>dir dst
 Directory of L:\BASINPAD\bench\dst

09/06/2026  09:32    <DIR>          .
09/06/2026  09:32    <DIR>          ..
09/06/2026  09:32    <DIR>          aaa1
09/06/2026  09:32    <SYMLINK>      aaa2 [aaa1]
               1 File(s)              0 bytes
               3 Dir(s)  11,395,715,072 bytes free

>dir src\aaa2\
 Directory of L:\BASINPAD\bench\src\aaa2

09/06/2026  09:32    <DIR>          .
09/06/2026  09:32    <DIR>          ..
09/06/2026  09:32    <DIR>          sub
               0 File(s)              0 bytes
               3 Dir(s)  11,395,715,072 bytes free

>dir dst\aaa2\
 Directory of L:\BASINPAD\bench\dst\aaa2

File Not Found
Dominant language
Rust
Stars
5.2k
Forks
107
Avg merge
2d 19h
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/coreutils

All issues in microsoft/coreutils

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.