Skip to content

Commit cc50118

Browse files
committed
Exclude the target directory from backups using CACHEDIR.TAG
This patch follows the lead of rust-lang#4386 (which excludes target directories from Time Machine backups) and is motived by the same reasons listen in rust-lang#3884. CACHEDIR.TAG is an OS-independent mechanism supported by Borg, restic, GNU Tar and other backup/archiving solutions. See https://bford.info/cachedir/ for more information about the specification. This has been discussed in Rust Internals earlier this year[1] and it seems like it's an uncontroversial improvement so I went ahead with the patch. [1] https://internals.rust-lang.org/t/pre-rfc-put-cachedir-tag-into-target/12262/11
1 parent 089cbb8 commit cc50118

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/cargo/core/compiler/layout.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,30 @@ impl Layout {
220220
}
221221
}
222222

223+
/// Marks the directory as excluded from archives/backups.
224+
///
225+
/// This is recommended to prevent derived/temporary files from bloating backups. There are two
226+
/// mechanisms used to achieve this right now:
227+
///
228+
/// * A dedicated resource property excluding from Time Machine backups on macOS
229+
/// * CACHEDIR.TAG files supported by various tools in a platform-independent way
230+
fn exclude_from_backups(path: &Path) {
231+
exclude_from_time_machine(path);
232+
let _ = std::fs::write(
233+
path.join("CACHEDIR.TAG"),
234+
"Signature: 8a477f597d28d172789f06886806bc55
235+
# This file is a cache directory tag created by cargo.
236+
# For information about cache directory tags see https://bford.info/cachedir/",
237+
);
238+
// Similarly to exclude_from_time_machine() we ignore errors here as it's an optional feature.
239+
}
240+
223241
#[cfg(not(target_os = "macos"))]
224-
fn exclude_from_backups(_: &Path) {}
242+
fn exclude_from_time_machine(path: &Path) {}
225243

226244
#[cfg(target_os = "macos")]
227245
/// Marks files or directories as excluded from Time Machine on macOS
228-
///
229-
/// This is recommended to prevent derived/temporary files from bloating backups.
230-
fn exclude_from_backups(path: &Path) {
246+
fn exclude_from_time_machine(path: &Path) {
231247
use core_foundation::base::TCFType;
232248
use core_foundation::{number, string, url};
233249
use std::ptr;

0 commit comments

Comments
 (0)