Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo's temp files cause backup churn on macOS #3884

Closed
kornelski opened this issue Mar 30, 2017 · 12 comments · Fixed by #4386
Closed

Cargo's temp files cause backup churn on macOS #3884

kornelski opened this issue Mar 30, 2017 · 12 comments · Fixed by #4386

Comments

@kornelski
Copy link
Contributor

kornelski commented Mar 30, 2017

macOS automatically makes hourly backups. Cargo's build temp files are large and frequently changing, causing gigabytes of redundant data backed up every day.

Because the temp files are in multiple project-relative locations, it's not practical for users to manually exclude all the target folders from backup.

Mac applications generally avoid this problem by using system-designed caches directory, but the issue for it (#1615) seems to be in a stalemate.

So I'm proposing an alternative quick fix that doesn't require changing any paths in Cargo. macOS allows excluding individual directories from backups. I suggest marking target/{build,deps,incremental} as excluded. It can be done with:

[URL setResourceValue: @YES] forKey: NSURLIsExcludedFromBackupKey error:nil];
@alexcrichton
Copy link
Member

Sounds like a nifty idea to me!

@cyplo
Copy link

cyplo commented Aug 6, 2017

What do you think about promoting this issue as beginner-friendly ?

@kornelski
Copy link
Contributor Author

kornelski commented Aug 6, 2017

For me the question is how to call ObjC method from Cargo. There are various approaches for this. Does Cargo have some crate/macro/.m files for this already? If not, any preference?

@alexcrichton
Copy link
Member

Perhaps the objc crate could be of assistance?

@kornelski
Copy link
Contributor Author

I've managed to implement marking using the objc crate:

https://gitlab.com/kornelski/exclude_from_backups/blob/master/src/macos.rs

Are you OK adding it as a dependency, or should I copy the code to Cargo?

@alexcrichton
Copy link
Member

Either's fine by me, although I'd slightly lean towards just copying it into Cargo as it may change over time. Thanks @pornel!

Out of curiosity, have you confirmed that this does indeed fix the problem?

@kornelski
Copy link
Contributor Author

I've verified that it sets com.apple.metadata:com_apple_backup_excludeItem extended attribute on files and directories, so the call works.

The feature requires macOS 10.8+, so I'll need to disable it on 10.7. Does Rust's CI run on 10.7? I don't have a 10.7 machine to test on.

@alexcrichton
Copy link
Member

Does this also solve the backup churn you were noticing?

Also yeah we'll need to work on 10.7 somehow, but it's ok to not add a test for this. Is it possible to just ignore errors on 10.7?

@kornelski
Copy link
Contributor Author

It may fail to link on 10.7. I'd have to use #[linkage = "extern_weak"].

@kornelski
Copy link
Contributor Author

I've verified that it prevents the backup churn (I've manually marked all target dirs, and none were in my latest backup).

@kornelski
Copy link
Contributor Author

I've also got a new implementation using servo/core-foundation-rs, which makes the code shorter.

@alexcrichton
Copy link
Member

Ok looks and sounds great to me!

bors added a commit that referenced this issue Aug 10, 2017
Exclude target directory from Time Machine

Fixes #3884
jstasiak added a commit to jstasiak/cargo that referenced this issue Jun 18, 2020
This patch follows the lead of rust-lang#4386 (which excludes target directories
from Time Machine backups) and is motived by the same reasons listen
in rust-lang#3884. CACHEDIR.TAG is an OS-independent mechanism supported by Borg,
restic, GNU Tar and other backup/archiving solutions.

See https://bford.info/cachedir/ for more information about the
specification. This has been discussed in Rust Internals earlier this
year[1] and it seems like it's an uncontroversial improvement so I went
ahead with the patch.

[1] https://internals.rust-lang.org/t/pre-rfc-put-cachedir-tag-into-target/12262/11
bors added a commit that referenced this issue Jul 2, 2020
Exclude the target directory from backups using CACHEDIR.TAG

This patch follows the lead of #4386 (which excludes target directories
from Time Machine backups) and is motived by the same reasons listen
in #3884. CACHEDIR.TAG is an OS-independent mechanism supported by Borg,
restic, GNU Tar and other backup/archiving solutions.

See https://bford.info/cachedir/ for more information about the
specification. This has been discussed in Rust Internals earlier this
year[1] and it seems like it's an uncontroversial improvement so I went
ahead with the patch.

One thing I'm wondering is whether this should maybe cover the whole main target directory (right now it applies to `target/debug`, `target/release` etc. but not to target root).

[1] https://internals.rust-lang.org/t/pre-rfc-put-cachedir-tag-into-target/12262/11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants