Skip to content

Commit

Permalink
refactor: centralize git checkouts and db paths
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Dec 20, 2023
1 parent a9c749c commit 0a4ce46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/cargo/core/global_cache_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,10 @@ impl GlobalCacheTracker {
) -> CargoResult<()> {
let _p = crate::util::profile::start("cleaning global cache files");
let config = clean_ctx.config;
let base_git_path = config.git_path().into_path_unlocked();
let base = BasePaths {
index: config.registry_index_path().into_path_unlocked(),
git_db: base_git_path.join("db"),
git_co: base_git_path.join("checkouts"),
git_db: config.git_db_path().into_path_unlocked(),
git_co: config.git_checkouts_path().into_path_unlocked(),
crate_dir: config.registry_cache_path().into_path_unlocked(),
src: config.registry_source_path().into_path_unlocked(),
};
Expand Down
9 changes: 6 additions & 3 deletions src/cargo/sources/git/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ impl<'cfg> Source for GitSource<'cfg> {
// exists.
exclude_from_backups_and_indexing(&git_path);

let db_path = git_path.join("db").join(&self.ident);
let db_path = self.config.git_db_path().join(&self.ident);
let db_path = db_path.into_path_unlocked();

let db = self.remote.db_at(&db_path).ok();
let (db, actual_rev) = match (self.locked_rev, db) {
Expand Down Expand Up @@ -305,10 +306,12 @@ impl<'cfg> Source for GitSource<'cfg> {
// Check out `actual_rev` from the database to a scoped location on the
// filesystem. This will use hard links and such to ideally make the
// checkout operation here pretty fast.
let checkout_path = git_path
.join("checkouts")
let checkout_path = self
.config
.git_checkouts_path()
.join(&self.ident)
.join(short_id.as_str());
let checkout_path = checkout_path.into_path_unlocked();
db.copy_to(actual_rev, &checkout_path, self.config)?;

let source_id = self
Expand Down
12 changes: 12 additions & 0 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ impl Config {
self.home_path.join("git")
}

/// Gets the directory of code sources Cargo checkouts from Git bare repos
/// (`<cargo_home>/git/checkouts`).
pub fn git_checkouts_path(&self) -> Filesystem {
self.git_path().join("checkouts")
}

/// Gets the directory for all Git bare repos Cargo clones
/// (`<cargo_home>/git/db`).
pub fn git_db_path(&self) -> Filesystem {
self.git_path().join("db")
}

/// Gets the Cargo base directory for all registry information (`<cargo_home>/registry`).
pub fn registry_base_path(&self) -> Filesystem {
self.home_path.join("registry")
Expand Down

0 comments on commit 0a4ce46

Please sign in to comment.