@@ -562,6 +562,33 @@ pub async fn link_package(
562
562
Ok ( paths)
563
563
}
564
564
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
+
565
592
/// Given an extracted package archive (`package_dir`), installs its files to
566
593
/// the `target_dir`.
567
594
///
@@ -587,6 +614,9 @@ pub fn link_package_sync(
587
614
// Ensure target directory exists
588
615
fs_err:: create_dir_all ( target_dir) . map_err ( InstallError :: FailedToCreateTargetDirectory ) ?;
589
616
617
+ #[ cfg( target_os = "macos" ) ]
618
+ exclude_from_backups ( Path :: new ( & target_prefix) ) ;
619
+
590
620
// Reuse or read the `paths.json` and `index.json` files from the package
591
621
// directory
592
622
let paths_json = options. paths_json . map_or_else (
0 commit comments