uutils / uutils/coreutils

cp: cannot copy attributes from one symlink to another

Open
#6,533 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - cp
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

Let's say we have a regular file, and two distinct symlinks pointing at it, owned by different users:

$ ln -s README.md symlink1
$ ln -s README.md symlink2
$ sudo chown -h root: symlink2
$ ls -l README.md symlink*
-rw-r--r-- 1 user user 7973 May  4 20:44 README.md
lrwxrwxrwx 1 user user    9 Jul  3 03:37 symlink1 -> README.md
lrwxrwxrwx 1 root root    9 Jul  3 03:37 symlink2 -> README.md

… then cp fails to handle --attributes-only correctly. There are two aspects to this, which may or may not be the same bug:

Aspect 1: Fails to notice that files are initially identical

$ cp --attributes-only -v symlink1 symlink2
cp: 'symlink1' and 'symlink2' are the same file
[$? = 1]
$ cargo run -q cp --attributes-only -v symlink1 symlink2
cp: cannot change attribute 'symlink2': Source file is a non regular file
[$? = 1]

Aspect 2: Fails consider that --attribute-only can be meaningful even on symlinks

$ cp -b --attributes-only -v symlink1 symlink2
'symlink1' -> 'symlink2' (backup: 'symlink2~')
$ ls -l README.md symlink*
-rw-r--r-- 1 user user 7973 May  4 20:44 README.md
lrwxrwxrwx 1 user user    9 Jul  3 03:37 symlink1 -> README.md
-rw-r--r-- 1 user user    0 Jul  3 03:42 symlink2
lrwxrwxrwx 1 root root    9 Jul  3 03:37 symlink2~ -> README.md
$ rm symlink2
$ mv symlink2~ symlink2  
$ cargo run -q cp -b --attributes-only -v symlink1 symlink2
cp: cannot change attribute 'symlink2': Source file is a non regular file
[$? = 1]

Found while reading #6496, but only remotely related.

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.

Research direction

Start by reproducing both symlink cases with the commands in the issue, using the repository's cargo run -q cp entry point and comparing the results with system cp. Trace the cp implementation to determine how --attributes-only handles identical symlinks and backups. Done means both reported cases behave correctly and the relevant command checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.