From ffe7559bb93b8ca704fa8f65c4eba3233e8f62b8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 7 Dec 2020 13:31:39 +0100 Subject: 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 --- src/filestore/path.rs | 16 +++++++++------- src/filestore/util.rs | 15 +++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'src/filestore') 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 { - 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> { 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(&self, mut ar: tar::Archive) -> 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 { - 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::>>()?; -- cgit v1.2.3