Skip to content

Commit 6e6cba5

Browse files
committed
refactor: add the remove_from_backup function and update the prefix
1 parent c01c460 commit 6e6cba5

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rattler/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ url = { workspace = true, features = ["serde"] }
5454
uuid = { workspace = true, features = ["v4", "fast-rng"] }
5555
console = { workspace = true, optional = true }
5656
serde_json.workspace = true
57+
core-foundation = "0.10.0"
5758

5859
[dev-dependencies]
5960
assert_matches = { workspace = true }

crates/rattler/src/install/mod.rs

+30
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,33 @@ pub async fn link_package(
562562
Ok(paths)
563563
}
564564

565+
#[cfg(target_os = "macos")]
566+
/// Marks files or directories as excluded from Time Machine on macOS
567+
///
568+
/// This is recommended to prevent derived/temporary files from bloating backups.
569+
/// <https://github.com/rust-lang/cargo/pull/7192>
570+
fn exclude_from_backups(path: &Path) {
571+
use core_foundation::base::TCFType;
572+
use core_foundation::{number, string, url};
573+
use std::ptr;
574+
575+
// For compatibility with 10.7 a string is used instead of global kCFURLIsExcludedFromBackupKey
576+
let is_excluded_key: Result<string::CFString, _> = "NSURLIsExcludedFromBackupKey".parse();
577+
let path = url::CFURL::from_path(path, false);
578+
if let (Some(path), Ok(is_excluded_key)) = (path, is_excluded_key) {
579+
unsafe {
580+
url::CFURLSetResourcePropertyForKey(
581+
path.as_concrete_TypeRef(),
582+
is_excluded_key.as_concrete_TypeRef(),
583+
number::kCFBooleanTrue.cast(),
584+
ptr::null_mut(),
585+
);
586+
}
587+
}
588+
// Errors are ignored, since it's an optional feature and failure
589+
// doesn't prevent Cargo from working
590+
}
591+
565592
/// Given an extracted package archive (`package_dir`), installs its files to
566593
/// the `target_dir`.
567594
///
@@ -587,6 +614,9 @@ pub fn link_package_sync(
587614
// Ensure target directory exists
588615
fs_err::create_dir_all(target_dir).map_err(InstallError::FailedToCreateTargetDirectory)?;
589616

617+
#[cfg(target_os = "macos")]
618+
exclude_from_backups(Path::new(&target_prefix));
619+
590620
// Reuse or read the `paths.json` and `index.json` files from the package
591621
// directory
592622
let paths_json = options.paths_json.map_or_else(

0 commit comments

Comments
 (0)