Skip to content

Commit 749654c

Browse files
committed
Auto merge of #13132 - arlosi:cachedir, r=epage
Avoid writing CACHEDIR.TAG if it already exists Cargo currently unconditionally writes `CACHEDIR.TAG` files even if they already exist. This practice causes problems for build systems that disallow multiple writes to the same file.
2 parents bdef274 + 04af5e7 commit 749654c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

crates/cargo-util/src/paths.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -719,14 +719,17 @@ pub fn exclude_from_backups_and_indexing(p: impl AsRef<Path>) {
719719
/// * CACHEDIR.TAG files supported by various tools in a platform-independent way
720720
fn exclude_from_backups(path: &Path) {
721721
exclude_from_time_machine(path);
722-
let _ = std::fs::write(
723-
path.join("CACHEDIR.TAG"),
724-
"Signature: 8a477f597d28d172789f06886806bc55
722+
let file = path.join("CACHEDIR.TAG");
723+
if !file.exists() {
724+
let _ = std::fs::write(
725+
file,
726+
"Signature: 8a477f597d28d172789f06886806bc55
725727
# This file is a cache directory tag created by cargo.
726728
# For information about cache directory tags see https://bford.info/cachedir/
727729
",
728-
);
729-
// Similarly to exclude_from_time_machine() we ignore errors here as it's an optional feature.
730+
);
731+
// Similarly to exclude_from_time_machine() we ignore errors here as it's an optional feature.
732+
}
730733
}
731734

732735
/// Marks the directory as excluded from content indexing.

0 commit comments

Comments
 (0)