diff options
Diffstat (limited to 'src/filestore')
-rw-r--r-- | src/filestore/merged.rs | 68 | ||||
-rw-r--r-- | src/filestore/path.rs | 4 | ||||
-rw-r--r-- | src/filestore/staging.rs | 5 | ||||
-rw-r--r-- | src/filestore/util.rs | 9 |
4 files changed, 22 insertions, 64 deletions
diff --git a/src/filestore/merged.rs b/src/filestore/merged.rs index d1bcfe7..c8ed90d 100644 --- a/src/filestore/merged.rs +++ b/src/filestore/merged.rs @@ -9,18 +9,17 @@ // use std::sync::Arc; - -use log::trace; -use tokio::sync::RwLock; +use std::path::Path; use anyhow::Result; use getset::Getters; +use log::trace; +use tokio::sync::RwLock; use crate::filestore::Artifact; +use crate::filestore::path::ArtifactPath; use crate::filestore::ReleaseStore; use crate::filestore::StagingStore; -use crate::package::PackageName; -use crate::package::PackageVersionConstraint; /// A type that merges the release store and the staging store /// @@ -40,55 +39,22 @@ impl MergedStores { MergedStores { release, staging } } - pub async fn get_artifact_by_name_and_version( - &self, - name: &PackageName, - version: &PackageVersionConstraint, - ) -> Result<Vec<Artifact>> { - let v = self - .staging - .read() - .await - .0 - .values() - .filter(|a| { - trace!( - "Checking {:?} == {:?} && {:?} == {:?}", - a.name(), - name, - version, - a.version() - ); - a.name() == name && version.matches(a.version()) - }) - .cloned() - .collect::<Vec<_>>(); - - if v.is_empty() { - Ok({ - self.release - .read() - .await - .0 - .values() - .filter(|a| a.name() == name && version.matches(a.version())) - .cloned() - .collect() - }) - } else { - Ok(v) - } - } - pub async fn get_artifact_by_path(&self, p: &Path) -> Result<Option<Artifact>> { + trace!("Fetching artifact from path: {:?}", p.display()); let artifact_path = ArtifactPath::new(p.to_path_buf())?; let staging = &mut self.staging.write().await.0; let staging_path = staging.root_path().join(&artifact_path)?; + trace!("staging_path = {:?}", staging_path.display()); if staging_path.exists() { - let art_path = ArtifactPath::new(p.to_path_buf())?; - let art = staging.load_from_path(&artifact_path)?; + let art = if let Some(art) = staging.get(&artifact_path) { + art + } else { + trace!("Loading path from staging store: {:?}", artifact_path.display()); + staging.load_from_path(&artifact_path)? + }; + return Ok(Some(art.clone())) } @@ -96,9 +62,15 @@ impl MergedStores { let release = &mut self.release.write().await.0; let release_path = release.root_path().join(&artifact_path)?; + trace!("release_path = {:?}", release_path); if release_path.exists() { - let art = release.load_from_path(&artifact_path)?; + let art = if let Some(art) = release.get(&artifact_path) { + art + } else { + trace!("Loading path from release store: {:?}", artifact_path.display()); + release.load_from_path(&artifact_path)? + }; return Ok(Some(art.clone())) } diff --git a/src/filestore/path.rs b/src/filestore/path.rs index 9262d1d..9ddc989 100644 --- a/src/filestore/path.rs +++ b/src/filestore/path.rs @@ -73,10 +73,6 @@ impl StoreRoot { FullArtifactPath(self, ap) } - pub(in crate::filestore) fn is_file(&self, subpath: &Path) -> bool { - self.0.join(subpath).is_file() - } - pub(in crate::filestore) fn is_dir(&self, subpath: &Path) -> bool { self.0.join(subpath).is_dir() } diff --git a/src/filestore/staging.rs b/src/filestore/staging.rs index 995768c..b944d84 100644 --- a/src/filestore/staging.rs +++ b/src/filestore/staging.rs @@ -9,7 +9,6 @@ // use std::fmt::Debug; -use std::path::Path; use anyhow::anyhow; use anyhow::Context; @@ -101,8 +100,4 @@ impl StagingStore { pub fn root_path(&self) -> &StoreRoot { self.0.root_path() } - - pub fn path_exists_in_store_root(&self, path: &Path) -> bool { - self.0.path_exists_in_store_root(path) - } } diff --git a/src/filestore/util.rs b/src/filestore/util.rs index c931545..2fc1483 100644 --- a/src/filestore/util.rs +++ b/src/filestore/util.rs @@ -12,7 +12,6 @@ //! use std::collections::BTreeMap; -use std::path::Path; use anyhow::anyhow; use anyhow::Result; @@ -51,12 +50,8 @@ impl FileStoreImpl { &self.root } - pub fn path_exists_in_store_root(&self, p: &Path) -> bool { - self.root.is_file(p) - } - - pub(in crate::filestore) fn values(&self) -> impl Iterator<Item = &Artifact> { - self.store.values() + pub fn get(&self, artifact_path: &ArtifactPath) -> Option<&Artifact> { + self.store.get(artifact_path) } pub(in crate::filestore) fn load_from_path( |