-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Mark temporary directories as excluded from macOS Spotlight #8686
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -547,3 +547,36 @@ fn exclude_from_time_machine(path: &Path) { | |
// Errors are ignored, since it's an optional feature and failure | ||
// doesn't prevent Cargo from working | ||
} | ||
|
||
/// Absolute path to an on-disk temporary directory. | ||
/// It may be system-wide or user-specific depending on system conventions. | ||
/// Used in layout.rs, only needed on Unix systems. | ||
#[cfg(unix)] | ||
pub fn persistent_temp_path() -> Option<PathBuf> { | ||
#[cfg(target_os = "macos")] | ||
{ | ||
// "Library/Caches" should be obtained via NSFileManager's | ||
// URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask | ||
// However, cocoa-foundation doesn't have bindings for it yet. | ||
// This path has remained stable for two decades, | ||
// so hardcode it for simplicity (dirs crate does the same). | ||
Some(home::home_dir()?.join("Library/Caches/Cargo")) | ||
} | ||
#[cfg(not(target_os = "macos"))] | ||
{ | ||
// XDG standard | ||
if let Some(path) = env::var_os("XDG_CACHE_HOME") { | ||
let path = PathBuf::from(path); | ||
if path.is_absolute() { | ||
return Some(path.join("cargo")); | ||
} | ||
} | ||
// FHS standard | ||
// This is not using /tmp, because /tmp could be using ramfs. | ||
let path = Path::new("/var/tmp"); | ||
if path.exists() { | ||
return Some(path.join("cargo")); | ||
} | ||
None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand this logic – is there any reason why it ignores the "important" part of XDG and instead does something completely different altogether in the "env not set" case? More generally, reimplementing the directory-selection logic seems to be a straight-forward route to bikeshed city (as demonstrated in the RFC). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What "important" part do you mean? I am afraid that touching XDG is going to attract bikeshed fiesta. I'm tempted to remove it for that reason, and go straight for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
XDG defines default directories if the env var is not set. The env var is probably not set in 99% of the cases, because people are fine with the defaults. Only "being XDG" when the env var is set ... if I wanted to troll people, that's how I would do it. ;-)
Did you consider simply using a library?
That's a cheap way out for this special case, but I'm not sure you want the next person following this precedent when they try to fix the issue for config/data files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've considered using a library, but it this area is full of abandoned projects and half-abandoned forks, so I didn't see any suitable crate. I think the best option would be to use a cargo-specific variable/setting for customizing this dir. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think no crate can help you if your intention is to invent your own non-standard scheme anyway.
That's of course technically possible, but is does nothing to resolve rust-lang/rfcs#1615 which is about sane defaults. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Jabs like that are unhelpful. Please don't do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have a nice day. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is a bit confusing, because cache and temp are usually different things and people people have different conceptions about them.