diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-07 13:31:39 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-07 13:31:39 +0100 |
commit | ffe7559bb93b8ca704fa8f65c4eba3233e8f62b8 (patch) | |
tree | 387950dc556bfe9d2daba168414f9eeb7b5a4c6b /src/filestore | |
parent | a9f696bdf2f54d2965a715bd79fc4d166267e20c (diff) |
Remove StoreRoot::stripped_from() and StoreRoot::walk()
This patch reduces the interface of StoreRoot even further.
The ::stripped_from() and ::walk() interfaces were removed and replaced
with a StoreRoot::find_artifacts_recursive() function, which returns an
iterator over the found ArtifactPath objects.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/filestore')
-rw-r--r-- | src/filestore/path.rs | 16 | ||||
-rw-r--r-- | src/filestore/util.rs | 15 |
2 files changed, 14 insertions, 17 deletions
diff --git a/src/filestore/path.rs b/src/filestore/path.rs index 3d87e73..9b60401 100644 --- a/src/filestore/path.rs +++ b/src/filestore/path.rs @@ -6,6 +6,8 @@ use anyhow::anyhow; use anyhow::Error; use anyhow::Result; use anyhow::Context; +use resiter::AndThen; +use resiter::Map; #[derive(Clone, Debug, PartialEq, Eq)] pub struct StoreRoot(PathBuf); @@ -23,12 +25,6 @@ impl StoreRoot { } } - pub (in crate::filestore) fn stripped_from(&self, pb: &Path) -> Result<ArtifactPath> { - pb.strip_prefix(&self.0) - .map_err(Error::from) - .and_then(|p| ArtifactPath::new(p.to_path_buf())) - } - pub fn join<'a>(&'a self, ap: &'a ArtifactPath) -> FullArtifactPath<'a> { FullArtifactPath(&self, ap) } @@ -45,8 +41,14 @@ impl StoreRoot { self.0.display() } - pub (in crate::filestore) fn walk(&self) -> walkdir::WalkDir { + pub fn find_artifacts_recursive(&self) -> impl Iterator<Item = Result<ArtifactPath>> { walkdir::WalkDir::new(&self.0) + .follow_links(false) + .into_iter() + .filter_entry(|e| e.file_type().is_file()) + .map_err(Error::from) + .map_ok(|de| de.into_path()) + .and_then_ok(ArtifactPath::new) } pub (in crate::filestore) fn unpack_archive_here<R>(&self, mut ar: tar::Archive<R>) -> Result<()> diff --git a/src/filestore/util.rs b/src/filestore/util.rs index 90dacab..b1e1506 100644 --- a/src/filestore/util.rs +++ b/src/filestore/util.rs @@ -4,12 +4,10 @@ use std::collections::BTreeMap; use std::path::Path; -use anyhow::Error; use anyhow::Result; use anyhow::anyhow; use indicatif::ProgressBar; use resiter::AndThen; -use resiter::Map; use crate::filestore::Artifact; use crate::filestore::path::*; @@ -28,15 +26,12 @@ pub struct FileStoreImpl { impl FileStoreImpl { /// Loads the passed path recursively into a Path => Artifact mapping pub fn load(root: StoreRoot, progress: ProgressBar) -> Result<Self> { - let store = root.walk() - .follow_links(false) - .into_iter() - .filter_entry(|e| e.file_type().is_file()) - .map_err(Error::from) - .and_then_ok(|f| { + let store = root + .find_artifacts_recursive() + .and_then_ok(|artifact_path| { progress.tick(); - let p = root.stripped_from(f.path())?; - Artifact::load(&root, p.clone()).map(|a| (p, a)) + Artifact::load(&root, artifact_path.clone()) + .map(|a| (artifact_path, a)) }) .collect::<Result<BTreeMap<ArtifactPath, Artifact>>>()?; |