From e308711e23ce1178417be5b4b299aec980a73165 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 12 Mar 2024 15:15:15 +0100 Subject: [PATCH 1/3] Add io::Error to display --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 2c5b192..43e19a9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,7 +22,7 @@ pub enum Error { #[error(transparent)] Io(#[from] std::io::Error), /// An I/O error occurred trying to access a specific path - #[error("I/O operation failed for path '{}'", .1)] + #[error("I/O operation failed for path '{}': {}", .1, .0)] IoPath(#[source] std::io::Error, crate::PathBuf), /// A user provided URL was invalid #[error(transparent)] From 4c8575caed7060ba56fa4989da279c38e0e034be Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 12 Mar 2024 15:15:49 +0100 Subject: [PATCH 2/3] 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`] From 93d0e821dea57068cb31c6fab9bac6b1195cce40 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 12 Mar 2024 15:18:23 +0100 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c01d7..5a9717a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Added +- [PR#52](https://github.com/EmbarkStudios/tame-index/pull/52) added `ComboIndexCache::cache_path` to retrieve the path of a particular crate's index entry. + ## [0.9.6] - 2024-03-12 ### Changed - [PR#51](https://github.com/EmbarkStudios/tame-index/pull/51) updated dependencies.