uutils / uutils/coreutils

cp: Should refuse to create broken symlinks to parent-dir

Open
#6,385 0 comments 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

Copying files as symbolic links to a new (sub-)directory would require constructing a relative path from the new location to the old, e.g. starting with ../.

Trying to do so would necessarily be very fragile. GNU cp even refuses to attempt it. However, uutils currently does it, very badly, resulting in completely broken links and exit code 0.

$ mkdir newdir  
$ cp -vs README.md newdir/  # GNU refuses to create broken symbolic links
'README.md' -> 'newdir/README.md'
cp: newdir/README.md: can make relative symbolic links only in current directory
[$? = 1]
$ ls newdir/  # It's empty
$ cargo run -q cp -vs README.md newdir/  # uutils returns "success"
'README.md' -> 'newdir/README.md'
$ ls newdir/  # And creates something
README.md
$ readlink newdir/README.md  # It creates a self-link
README.md
$ less newdir/README.md 
newdir/README.md: Too many levels of symbolic links
[$? = 1]

Discovered while reviewing #6380.

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 with the cp command entry point and reproduce the issue using the cargo run -q cp -vs README.md newdir/ example. Trace relative symlink handling for a destination subdirectory, then verify that the command refuses the operation with a nonzero exit status and does not create the broken link.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.