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

Exclude target directory from Time Machine #4386

Merged
merged 1 commit into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ url = "1.1"
[target.'cfg(unix)'.dependencies]
openssl = "0.9"

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = { version = "0.4.4", features = ["mac_os_10_7_support"] }

[target.'cfg(windows)'.dependencies]
advapi32-sys = "0.2"
kernel32-sys = "0.2"
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ extern crate tempdir;
extern crate termcolor;
extern crate toml;
extern crate url;
#[cfg(target_os = "macos")]
extern crate core_foundation;

use std::fmt;
use std::error::Error;
Expand Down
31 changes: 31 additions & 0 deletions src/cargo/ops/cargo_rustc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,42 @@ impl Layout {
})
}

#[cfg(not(target_os = "macos"))]
fn exclude_from_backups(&self, _: &Path) {}

#[cfg(target_os = "macos")]
/// Marks files or directories as excluded from Time Machine on macOS
///
/// This is recommended to prevent derived/temporary files from bloating backups.
fn exclude_from_backups(&self, path: &Path) {
use std::ptr;
use core_foundation::{url, number, string};
use core_foundation::base::TCFType;

// For compatibility with 10.7 a string is used instead of global kCFURLIsExcludedFromBackupKey
let is_excluded_key: Result<string::CFString, _> = "NSURLIsExcludedFromBackupKey".parse();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can perhaps avoid some indentation issues here with:

let is_excluded_key: string::CFString = match ... {
    Ok(k) => k,
    Err(_) => return,
};
// ...

match (url::CFURL::from_path(path, false), is_excluded_key) {
(Some(path), Ok(is_excluded_key)) => unsafe {
url::CFURLSetResourcePropertyForKey(
path.as_concrete_TypeRef(),
is_excluded_key.as_concrete_TypeRef(),
number::kCFBooleanTrue as *const _,
ptr::null_mut(),
);
},
// Errors are ignored, since it's an optional feature and failure
// doesn't prevent Cargo from working
_ => {}
}
}

pub fn prepare(&mut self) -> io::Result<()> {
if fs::metadata(&self.root).is_err() {
fs::create_dir_all(&self.root)?;
}

self.exclude_from_backups(&self.root);

mkdir(&self.deps)?;
mkdir(&self.native)?;
mkdir(&self.incremental)?;
Expand Down