Skip to content

cargo clean when target is a symlink only deletes symlink #7510

@jonhoo

Description

@jonhoo

Problem
If CARGO_TARGET_DIR is set to a path that is a symlink, or target itself is a symlink, cargo clean will delete the symlink and not anything in the linked directory.

Steps

  1. mkdir foo
  2. ln -sfn foo target
  3. cargo build
  4. cargo clean
  5. ls foo
  6. ls target

Expected: foo should be empty, target should still point to foo
Actual: foo has all build artifacts, target has been removed.

Possible Solution(s)
If cargo's target directory is a symlink, it should remove the contents of the symlink rather than the symlink itself.

Output of cargo version:
cargo 1.38.0 (23ef9a4 2019-08-20)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    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