Skip to content

Exclude cache directories from iCloud Drive sync on macOS #16724

@hguandl

Description

@hguandl

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:

// 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cachingArea: caching of dependencies, repositories, and build artifactsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`O-macosOS: macOSS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions