Skip to content

Commit 3324348

Browse files
committed
Mark $CARGO_HOME/{registry,git} as cache directories
This follows rust-langGH-8378 which applies this technique to target directories inside projects. With the patch two large-ish throwaway directories are also excluded from backups. I decided against excluding $CARGO_HOME/bin or $CARGO_HOME as a whole, because there may be important binaries needed by a user to run their system and there are credentials in the credentials file – I'm happy to simplify this and exclude whole $CARGO_HOME though.
1 parent c68c622 commit 3324348

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ impl GitRemote {
220220
if into.exists() {
221221
paths::remove_dir_all(into)?;
222222
}
223+
paths::create_dir_all_excluded_from_backups_atomic(
224+
cargo_config.home().join("git").as_path_unlocked(),
225+
)?;
223226
paths::create_dir_all(into)?;
224227
let mut repo = init(into, true)?;
225228
fetch(&mut repo, self.url.as_str(), reference, cargo_config)

src/cargo/sources/registry/remote.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ impl<'cfg> RemoteRegistry<'cfg> {
7373
Ok(repo) => Ok(repo),
7474
Err(_) => {
7575
drop(paths::remove_dir_all(&path));
76+
paths::create_dir_all_excluded_from_backups_atomic(
77+
self.config.home().join("registry").as_path_unlocked(),
78+
)?;
7679
paths::create_dir_all(&path)?;
7780

7881
// Note that we'd actually prefer to use a bare repository

0 commit comments

Comments
 (0)