From 04af5e7a061c2ab1980e92eaa0ca480c276b0d23 Mon Sep 17 00:00:00 2001 From: Arlo Siemsen Date: Thu, 7 Dec 2023 14:49:30 -0600 Subject: [PATCH] Avoid writing CACHEDIR.TAG if it already exists --- crates/cargo-util/src/paths.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/cargo-util/src/paths.rs b/crates/cargo-util/src/paths.rs index f405c8f9742..743e3f3a88e 100644 --- a/crates/cargo-util/src/paths.rs +++ b/crates/cargo-util/src/paths.rs @@ -719,14 +719,17 @@ pub fn exclude_from_backups_and_indexing(p: impl AsRef) { /// * CACHEDIR.TAG files supported by various tools in a platform-independent way fn exclude_from_backups(path: &Path) { exclude_from_time_machine(path); - let _ = std::fs::write( - path.join("CACHEDIR.TAG"), - "Signature: 8a477f597d28d172789f06886806bc55 + let file = path.join("CACHEDIR.TAG"); + if !file.exists() { + let _ = std::fs::write( + file, + "Signature: 8a477f597d28d172789f06886806bc55 # This file is a cache directory tag created by cargo. # For information about cache directory tags see https://bford.info/cachedir/ ", - ); - // Similarly to exclude_from_time_machine() we ignore errors here as it's an optional feature. + ); + // Similarly to exclude_from_time_machine() we ignore errors here as it's an optional feature. + } } /// Marks the directory as excluded from content indexing.