tarka / xcp

An extended `cp`
GNU General Public License v3.0
747 stars 24 forks source link

Please support --no-dereference #52

Open wez opened 4 months ago

wez commented 4 months ago

From man cp:

       -P, --no-dereference
              never follow symbolic links in SOURCE

The intended outcome is, rather than treating a symlink to a dir as a directory that should be recursively copied, the destination should itself be a symlink with the same target.

Thank you for creating this utility!

tarka commented 4 months ago

Hi @wez, I'm happy to add this, but I'm not sure I understand your underlying issue ATM. By default xcp does not dereference symlinks; in-fact can't, which is a missing feature. Also cp doesn't dereference by default. e.g:

# mkdir source
# cd source/
# echo data > file
# ln -s file file-link
# ln -s /etc/ .
# mkdir dir
# ln -s dir/ dir-link
# cd dir
# ln -s ../file file-link
# cd ../../

# cp -p --recursive --no-dereference source cp-noderef
# cp -p --recursive source cp-default
# xcp --recursive source xcp-default

# tree source/ cp-default/ cp-noderef/ xcp-default/
source/
├── dir
│   └── file-link -> ../file
├── dir-link -> dir/
├── file
└── file-link -> file
cp-default/
├── dir
│   └── file-link -> ../file
├── dir-link -> dir/
├── file
└── file-link -> file
cp-noderef/
├── dir
│   └── file-link -> ../file
├── dir-link -> dir/
├── file
└── file-link -> file
xcp-default/
├── dir
│   └── file-link -> ../file
├── dir-link -> dir/
├── file
└── file-link -> file

I'm missing something here, can you provide a concrete example of a broken and working copy with cp?

Thank you for creating this utility!

You're welcome! I'm glad somebody finds it useful.