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 fooln -sfn foo targetcargo buildcargo cleanls fools targetExpected: 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)
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.
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.