Skip to content

cp: symlink overwrite-detection is broken #6265

@BenWiederhake

Description

@BenWiederhake

Steps to reproduce:

  • Create two regular files, README.md and good/README.md, and an initially-empty directory tmp/.
  • Inside tmp, create an empty regular file foo, and a symlink README.md that points to foo.
  • Try to copy README.md and good/README.md to tmp/

Expected result: README.md is copied to tmp/ into the file foo, and the second attempt is aborted, leading to an error message and a non-zero (failure) exit code.

Actual result: README.md is copied to tmp/ into the file foo, and the second attempt is successful, leading to foo containing the contents of the second file, no error message, and a zero (success) exit code.

Demonstrator:

$ mkdir -p good && cp README.md good/README.md
$ rm -rf tmp/ && mkdir tmp/ && ln -s foo tmp/README.md && touch tmp/foo
$ ../gnu/src/cp README.md good/README.md tmp # Yes error!
../gnu/src/cp: will not copy 'good/README.md' through just-created symlink 'tmp/README.md'
[$? = 1]
$
$ mkdir -p good && cp README.md good/README.md
$ rm -rf tmp/ && mkdir tmp/ && ln -s foo tmp/README.md && touch tmp/foo
$ cargo run cp README.md good/README.md tmp # No error?!
$

Found while reviewing #6208

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions