From 4c8575caed7060ba56fa4989da279c38e0e034be Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 12 Mar 2024 15:15:49 +0100 Subject: [PATCH] Add ComboIndexCache::cache_path --- src/index.rs | 13 +++++++++++-- src/index/local.rs | 11 ++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/index.rs b/src/index.rs index 314d056..40f27bb 100644 --- a/src/index.rs +++ b/src/index.rs @@ -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, @@ -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 diff --git a/src/index/local.rs b/src/index/local.rs index 45fb08b..3035a9c 100644 --- a/src/index/local.rs +++ b/src/index/local.rs @@ -136,7 +136,7 @@ impl LocalRegistry { name: KrateName<'_>, _lock: &FileLock, ) -> Result, 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, @@ -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`]