Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [main] - TBD
- Add CACHEDIR.TAG to idf and pio temporary directories, to prevent Linux backups
from picking them up (see TODO, no support is added for MacOS/Windows).

## [0.33.1] - 2025-07-27
- Fix a bug where the cmake utilities refused to work with CMake 4 due to a broken version check

Expand Down
1 change: 1 addition & 0 deletions src/espidf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ impl Installer {
install_dir.display()
)
})?;
crate::fs::exclude_from_backups(&install_dir);

let (esp_idf_dir, managed_repo) = match self.esp_idf_origin {
EspIdfOrigin::Managed(managed) => (
Expand Down
24 changes: 24 additions & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ use std::path::Path;

use anyhow::Result;

/// Marks the directory as excluded from archives/backups by writing a `CACHEDIR.TAG` file.
///
/// This prevents derived/temporary files from bloating backups. Errors are ignored since
/// this is an optional best-effort feature.
///
/// See the [Cache Directory Tagging Specification](https://bford.info/cachedir/).
///
/// TODO: This only replicates _part_ of what cargo_util::paths::exclude_from_backups_and_indexing does:
/// https://doc.rust-lang.org/beta/nightly-rustc/cargo_util/paths/fn.exclude_from_backups_and_indexing.html
/// we should consider lifting more of the code to prevent backup on MacOS, and indexing on Windows.
pub fn exclude_from_backups(path: &Path) {
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 embuild.
# For information about cache directory tags see https://bford.info/cachedir/
",
);
// We ignore errors here as it's an optional feature.
}
}

/// Copy `src_file` to `dest_file_or_dir` if `src_file` is different or the destination
/// file doesn't exist.
///
Expand Down
1 change: 1 addition & 0 deletions src/pio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl Pio {
if !pio_dir.exists() {
fs::create_dir_all(pio_dir)?;
}
crate::fs::exclude_from_backups(pio_dir);

pio_installer.pio(pio_dir);
}
Expand Down
Loading