Skip to content

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

@basinilya

Description

@basinilya

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugIt shouldn't be doing this.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions