mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Mark .cargo/git and .cargo/registry as cache dirs
Fixes #10457 (but still needs tests)
This commit is contained in:
parent
4777c22168
commit
ce9a6ab648
@ -632,7 +632,7 @@ pub fn create_dir_all_excluded_from_backups_atomic(p: impl AsRef<Path>) -> Resul
|
||||
let parent = path.parent().unwrap();
|
||||
let base = path.file_name().unwrap();
|
||||
create_dir_all(parent)?;
|
||||
// We do this in two steps (first create a temporary directory and exlucde
|
||||
// We do this in two steps (first create a temporary directory and exclude
|
||||
// it from backups, then rename it to the desired name. If we created the
|
||||
// directory directly where it should be and then excluded it from backups
|
||||
// we would risk a situation where cargo is interrupted right after the directory
|
||||
@ -660,6 +660,14 @@ pub fn create_dir_all_excluded_from_backups_atomic(p: impl AsRef<Path>) -> Resul
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Mark an existing directory as excluded from backups and indexing.
|
||||
pub fn exclude_from_backups_and_indexing(p: impl AsRef<Path>) -> Result<()> {
|
||||
let path = p.as_ref();
|
||||
exclude_from_backups(path);
|
||||
exclude_from_content_indexing(path);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Marks the directory as excluded from archives/backups.
|
||||
///
|
||||
/// This is recommended to prevent derived/temporary files from bloating backups. There are two
|
||||
|
@ -7,6 +7,7 @@ use crate::util::errors::CargoResult;
|
||||
use crate::util::hex::short_hash;
|
||||
use crate::util::Config;
|
||||
use anyhow::Context;
|
||||
use cargo_util::paths::exclude_from_backups_and_indexing;
|
||||
use log::trace;
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
use std::task::Poll;
|
||||
@ -122,8 +123,20 @@ impl<'cfg> Source for GitSource<'cfg> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let git_path = self.config.git_path();
|
||||
let git_path = self.config.assert_package_cache_locked(&git_path);
|
||||
let git_fs = self.config.git_path();
|
||||
git_fs.create_dir()?;
|
||||
let git_path = self.config.assert_package_cache_locked(&git_fs);
|
||||
|
||||
// Before getting a checkout, make sure that `<cargo_home>/git` is
|
||||
// marked as excluded from indexing and backups. Older versions of Cargo
|
||||
// didn't do this, so we do it here regardless of whether `<cargo_home>`
|
||||
// exists.
|
||||
//
|
||||
// This does not use `create_dir_all_excluded_from_backups_atomic` for
|
||||
// the same reason: we want to exclude it even if the directory already
|
||||
// exists.
|
||||
exclude_from_backups_and_indexing(&git_path)?;
|
||||
|
||||
let db_path = git_path.join("db").join(&self.ident);
|
||||
|
||||
let db = self.remote.db_at(&db_path).ok();
|
||||
|
@ -167,6 +167,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::task::Poll;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use cargo_util::paths::exclude_from_backups_and_indexing;
|
||||
use flate2::read::GzDecoder;
|
||||
use log::debug;
|
||||
use semver::Version;
|
||||
@ -552,6 +553,19 @@ impl<'cfg> RegistrySource<'cfg> {
|
||||
} else {
|
||||
Box::new(remote::RemoteRegistry::new(source_id, config, &name)) as Box<_>
|
||||
};
|
||||
|
||||
// Before starting to work on the registry, make sure that
|
||||
// `<cargo_home>/registry` is marked as excluded from indexing and
|
||||
// backups. Older versions of Cargo didn't do this, so we do it here
|
||||
// regardless of whether `<cargo_home>` exists.
|
||||
//
|
||||
// This does not use `create_dir_all_excluded_from_backups_atomic` for
|
||||
// the same reason: we want to exclude it even if the directory already
|
||||
// exists.
|
||||
let registry_base = config.registry_base_path();
|
||||
registry_base.create_dir()?;
|
||||
exclude_from_backups_and_indexing(®istry_base.into_path_unlocked())?;
|
||||
|
||||
Ok(RegistrySource::new(
|
||||
source_id,
|
||||
config,
|
||||
|
@ -315,19 +315,24 @@ impl Config {
|
||||
self.home_path.join("git")
|
||||
}
|
||||
|
||||
/// Gets the Cargo base directory for all registry information (`<cargo_home>/registry`).
|
||||
pub fn registry_base_path(&self) -> Filesystem {
|
||||
self.home_path.join("registry")
|
||||
}
|
||||
|
||||
/// Gets the Cargo registry index directory (`<cargo_home>/registry/index`).
|
||||
pub fn registry_index_path(&self) -> Filesystem {
|
||||
self.home_path.join("registry").join("index")
|
||||
self.registry_base_path().join("index")
|
||||
}
|
||||
|
||||
/// Gets the Cargo registry cache directory (`<cargo_home>/registry/path`).
|
||||
pub fn registry_cache_path(&self) -> Filesystem {
|
||||
self.home_path.join("registry").join("cache")
|
||||
self.registry_base_path().join("cache")
|
||||
}
|
||||
|
||||
/// Gets the Cargo registry source directory (`<cargo_home>/registry/src`).
|
||||
pub fn registry_source_path(&self) -> Filesystem {
|
||||
self.home_path.join("registry").join("src")
|
||||
self.registry_base_path().join("src")
|
||||
}
|
||||
|
||||
/// Gets the default Cargo registry.
|
||||
|
Loading…
x
Reference in New Issue
Block a user