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
mkdir foo
ln -sfn foo target
cargo build
cargo clean
ls foo
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)
Problem
If
CARGO_TARGET_DIRis set to a path that is a symlink, ortargetitself is a symlink,cargo cleanwill delete the symlink and not anything in the linked directory.Steps
mkdir fooln -sfn foo targetcargo buildcargo cleanls fools targetExpected:
fooshould be empty,targetshould still point tofooActual:
foohas all build artifacts,targethas 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)