Skip to content

cargo clean -p removes fingerprints for any package that shares a prefix with the target #10069

Closed
@jonhoo

Description

@jonhoo

Problem

cargo clean -p foo will remove the fingerprint files for all crates that start with foo- due to this glob:

let pkg_dir = format!("{}-*", pkg.name());

Steps

#!/bin/bash
rm -rf clean-any-prefix
mkdir clean-any-prefix
cd clean-any-prefix

cargo new foo
cd foo
echo 'tracing-subscriber = { version = "*", default-features = false }' >> Cargo.toml
echo 'tracing = { version = "*", default-features = false }' >> Cargo.toml
cargo check
cp -r target target.old
cargo clean -p tracing
diff -qr target.old target | grep subscriber
Only in target.old/debug/.fingerprint: tracing-subscriber-4444b7d26073268f

Possible Solution(s)

This one is trickier to fix than #10068. The "best" option is likely to walk all the versions in the Resolve and remove each one explicitly rather than relying on a glob. This would also allow addressing this TODO:

if spec.version().is_some() {
config.shell().warn(&format!(
"version qualifier in `-p {}` is ignored, \
cleaning all versions of `{}` found",
spec_str,
spec.name()
))?;
}

Barring that, the removal could walk the results of the glob and then do filtering using something that checks for exactly {pkg.name()}-{semver-pattern} (maybe with a regex).

Notes

No response

Version

cargo 1.56.0 (4ed5d137b 2021-10-04)
release: 1.56.0
commit-hash: 4ed5d137baff5eccf1bae5a7b2ae4b57efad4a7d
commit-date: 2021-10-04

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions