Skip to content

Commit

Permalink
Add ComboIndexCache::cache_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Mar 12, 2024
1 parent e308711 commit 4c8575c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ pub enum ComboIndexCache {
}

impl ComboIndexCache {
/// Retrieves the index metadata for the specified crate name, optionally
/// writing a cache entry for it if there was not already an up to date one
/// Retrieves the index metadata for the specified crate name
#[inline]
pub fn cached_krate(
&self,
Expand All @@ -131,6 +130,16 @@ impl ComboIndexCache {
}
}

/// Gets the path to the cache entry for the specified crate
pub fn cache_path(&self, name: crate::KrateName<'_>) -> crate::PathBuf {
match self {
Self::Git(index) => index.cache.cache_path(name),
Self::Sparse(index) => index.cache().cache_path(name),
#[cfg(feature = "local")]
Self::Local(lr) => lr.krate_path(name),
}
}

/// Constructs a [`Self`] for the specified index.
///
/// See [`Self::crates_io`] if you want to create a crates.io index based
Expand Down
11 changes: 10 additions & 1 deletion src/index/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl LocalRegistry {
name: KrateName<'_>,
_lock: &FileLock,
) -> Result<Option<IndexKrate>, Error> {
let index_path = make_path(&self.path, name);
let index_path = self.krate_path(name);

let buf = match std::fs::read(&index_path) {
Ok(buf) => buf,
Expand All @@ -146,6 +146,15 @@ impl LocalRegistry {

Ok(Some(IndexKrate::from_slice(&buf)?))
}

/// Gets the path to the index entry for the krate.
///
/// Note that unlike .cache entries for git and sparse indices, these are not
/// binary files, they are just the JSON line format
#[inline]
pub fn krate_path(&self, name: KrateName<'_>) -> PathBuf {
make_path(&self.path, name)
}
}

/// Allows the building of a local registry from a [`RemoteGitIndex`] or [`RemoteSparseIndex`]
Expand Down

0 comments on commit 4c8575c

Please sign in to comment.