- Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Problem
Currently, Cargo kindly excludes cache directories (e.g., target/) from Time Machine backups on macOS. For the same reasons, we should also prevent iCloud Drive from syncing these directories when a project is located in an iCloud-synced folder (e.g., ~/Desktop or ~/Documents).
Proposed Solution
We can simply add the iCloud exclusion property alongside the existing implementation of Time Machine exclusion:
cargo/crates/cargo-util/src/paths.rs
Lines 855 to 867 in 607b3eb
| // For compatibility with 10.7 a string is used instead of global kCFURLIsExcludedFromBackupKey | |
| let is_excluded_key: Result<string::CFString, _> = "NSURLIsExcludedFromBackupKey".parse(); | |
| let path = url::CFURL::from_path(path, false); | |
| if let (Some(path), Ok(is_excluded_key)) = (path, is_excluded_key) { | |
| unsafe { | |
| url::CFURLSetResourcePropertyForKey( | |
| path.as_concrete_TypeRef(), | |
| is_excluded_key.as_concrete_TypeRef(), | |
| number::kCFBooleanTrue as *const _, | |
| ptr::null_mut(), | |
| ); | |
| } | |
| } |
The key kCFURLUbiquitousItemIsExcludedFromSyncKey, introduced in macOS 11.3, tells iCloud Drive to ignore the directory. For compatibility, we can use the string value "NSURLUbiquitousItemIsExcludedFromSyncKey".
Following the existing pattern, we can safely set this property and keep it backward-compatible.
Notes
I would be happy to submit a PR for this if the team agrees!