cargo clean when target is a symlink only deletes symlink

Created on 14 Oct 2019  路  2Comments  路  Source: rust-lang/cargo

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 (23ef9a4ef 2019-08-20)

C-bug

Most helpful comment

Sorry for commenting on closed issue. I was following the video where @jonhoo did fix this issue. Even though it was closed as expected behavior, I feel it will be better to provide some info to user who did use symlink as target. Either at the beginning of project or when user does clean. Like: "Since the target directory is a symlink cargo doesn't modify actual target, but only deletes symlink upon clean" Or some better message.

All 2 comments

I'm going to close this as expected behavior, see discussion in #7527.

Sorry for commenting on closed issue. I was following the video where @jonhoo did fix this issue. Even though it was closed as expected behavior, I feel it will be better to provide some info to user who did use symlink as target. Either at the beginning of project or when user does clean. Like: "Since the target directory is a symlink cargo doesn't modify actual target, but only deletes symlink upon clean" Or some better message.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

japaric picture japaric  路  3Comments

JustAPerson picture JustAPerson  路  3Comments

fprijate picture fprijate  路  3Comments

SimonSapin picture SimonSapin  路  3Comments

ehuss picture ehuss  路  3Comments