summaryrefslogtreecommitdiffstats
path: root/src/filestore
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-02-07 12:35:33 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-02-08 09:37:04 +0100
commitd319579fc89b5ac09f10abf4bfc77c21b0fc65ce (patch)
treee4fb352f3c1cd98383955d08c20fc0d311db51b7 /src/filestore
parent31fb8c89fefd3167b8b928cd75ddc008da60b434 (diff)
Remove `Artifact` type
This patch follows-up on the shrinking of the `Artifact` type and removes it entirely. The type is not needed. Only the `ArtifactPath` type is needed, which is a thin wrapper around `PathBuf`, ensuring that the path is relative to the store root. The `Artifact` type used `pom` to parse the name and version of the package from the `ArtifactPath` object it contained, which resulted in the restriction that the path must always be <name>-<version>... Which should not be a requirement and actually caused issues with a package named "foo-bar" (as an example). Signed-off-by: Matthias Beyer <matthias.beyer@atos.net> Tested-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/filestore')
-rw-r--r--src/filestore/artifact.rs30
-rw-r--r--src/filestore/merged.rs7
-rw-r--r--src/filestore/mod.rs4
-rw-r--r--src/filestore/path.rs2
-rw-r--r--src/filestore/staging.rs19
-rw-r--r--src/filestore/util.rs37
6 files changed, 27 insertions, 72 deletions
diff --git a/src/filestore/artifact.rs b/src/filestore/artifact.rs
deleted file mode 100644
index 2f3477a..0000000
--- a/src/filestore/artifact.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-//
-// Copyright (c) 2020-2021 science+computing ag and other contributors
-//
-// This program and the accompanying materials are made
-// available under the terms of the Eclipse Public License 2.0
-// which is available at https://www.eclipse.org/legal/epl-2.0/
-//
-// SPDX-License-Identifier: EPL-2.0
-//
-
-use anyhow::Result;
-use getset::Getters;
-
-use crate::filestore::path::ArtifactPath;
-use crate::filestore::path::StoreRoot;
-
-#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Getters)]
-pub struct Artifact {
- #[getset(get = "pub")]
- path: ArtifactPath,
-}
-
-impl Artifact {
- pub fn load(_root: &StoreRoot, path: ArtifactPath) -> Result<Self> {
- Ok(Artifact {
- path,
- })
- }
-}
-
diff --git a/src/filestore/merged.rs b/src/filestore/merged.rs
index 0b19d85..4c7a38b 100644
--- a/src/filestore/merged.rs
+++ b/src/filestore/merged.rs
@@ -21,7 +21,6 @@ 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;
@@ -45,7 +44,7 @@ impl MergedStores {
MergedStores { release, staging }
}
- pub async fn get_artifact_by_path(&self, p: &Path) -> Result<Option<Artifact>> {
+ pub async fn get_artifact_by_path(&self, p: &Path) -> Result<Option<ArtifactPath>> {
trace!("Fetching artifact from path: {:?}", p.display());
let artifact_path = ArtifactPath::new(p.to_path_buf())?;
@@ -58,7 +57,7 @@ impl MergedStores {
art
} else {
trace!("Loading path from staging store: {:?}", artifact_path.display());
- staging.load_from_path(&artifact_path)?
+ staging.load_from_path(&artifact_path)
};
return Ok(Some(art.clone()))
@@ -73,7 +72,7 @@ impl MergedStores {
art
} else {
trace!("Loading path from release store: {:?}", artifact_path.display());
- release.load_from_path(&artifact_path)?
+ release.load_from_path(&artifact_path)
};
return Ok(Some(art.clone()))
}
diff --git a/src/filestore/mod.rs b/src/filestore/mod.rs
index 0d19d02..29eb476 100644
--- a/src/filestore/mod.rs
+++ b/src/filestore/mod.rs
@@ -8,9 +8,6 @@
// SPDX-License-Identifier: EPL-2.0
//
-mod artifact;
-pub use artifact::*;
-
mod release;
pub use release::*;
@@ -21,5 +18,6 @@ mod merged;
pub use merged::*;
pub mod path;
+pub use path::ArtifactPath;
mod util;
diff --git a/src/filestore/path.rs b/src/filestore/path.rs
index c38c114..a03ab83 100644
--- a/src/filestore/path.rs
+++ b/src/filestore/path.rs
@@ -94,7 +94,7 @@ impl StoreRoot {
}
}
-#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
+#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ArtifactPath(PathBuf);
impl ArtifactPath {
diff --git a/src/filestore/staging.rs b/src/filestore/staging.rs
index 788cd02..1c2a848 100644
--- a/src/filestore/staging.rs
+++ b/src/filestore/staging.rs
@@ -10,16 +10,15 @@
use std::fmt::Debug;
-use anyhow::anyhow;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
+use anyhow::anyhow;
use futures::stream::Stream;
use indicatif::ProgressBar;
use log::trace;
use result_inspect::ResultInspect;
-use crate::filestore::Artifact;
use crate::filestore::path::ArtifactPath;
use crate::filestore::path::StoreRoot;
use crate::filestore::util::FileStoreImpl;
@@ -84,14 +83,12 @@ impl StagingStore {
None
} else {
Some({
- ArtifactPath::new(path).and_then(|ap| {
- self.0
- .load_from_path(&ap)
- .inspect(|r| trace!("Loaded from path {} = {:?}", ap.display(), r))
- .with_context(|| anyhow!("Loading from path: {}", ap.display()))
- .map_err(Error::from)
- .map(|art| art.path().clone())
- })
+ // Clippy doesn't detect this properly
+ #[allow(clippy::redundant_clone)]
+ ArtifactPath::new(path.to_path_buf())
+ .inspect(|r| trace!("Loaded from path {} = {:?}", path.display(), r))
+ .with_context(|| anyhow!("Loading from path: {}", path.display()))
+ .map(|ap| self.0.load_from_path(&ap).clone())
})
}
})
@@ -102,7 +99,7 @@ impl StagingStore {
self.0.root_path()
}
- pub fn get(&self, p: &ArtifactPath) -> Option<&Artifact> {
+ pub fn get(&self, p: &ArtifactPath) -> Option<&ArtifactPath> {
self.0.get(p)
}
}
diff --git a/src/filestore/util.rs b/src/filestore/util.rs
index 2fc1483..0d98404 100644
--- a/src/filestore/util.rs
+++ b/src/filestore/util.rs
@@ -11,15 +11,13 @@
//! Module containing utilities for the filestore implementation
//!
-use std::collections::BTreeMap;
+use std::collections::HashSet;
-use anyhow::anyhow;
use anyhow::Result;
use indicatif::ProgressBar;
-use resiter::AndThen;
-use crate::filestore::path::*;
-use crate::filestore::Artifact;
+use crate::filestore::path::ArtifactPath;
+use crate::filestore::path::StoreRoot;
/// The actual filestore implementation
///
@@ -29,19 +27,16 @@ use crate::filestore::Artifact;
/// It can then be wrapped into the actual interface of this module with specialized functionality.
pub struct FileStoreImpl {
pub(in crate::filestore) root: StoreRoot,
- store: BTreeMap<ArtifactPath, Artifact>,
+ store: HashSet<ArtifactPath>,
}
impl FileStoreImpl {
- /// Loads the passed path recursively into a Path => Artifact mapping
+ /// Loads the passed path recursively
pub fn load(root: StoreRoot, progress: ProgressBar) -> Result<Self> {
let store = root
.find_artifacts_recursive()
- .and_then_ok(|artifact_path| {
- progress.tick();
- Artifact::load(&root, artifact_path.clone()).map(|a| (artifact_path, a))
- })
- .collect::<Result<BTreeMap<ArtifactPath, Artifact>>>()?;
+ .inspect(|_| progress.tick())
+ .collect::<Result<HashSet<ArtifactPath>>>()?;
Ok(FileStoreImpl { root, store })
}
@@ -50,21 +45,17 @@ impl FileStoreImpl {
&self.root
}
- pub fn get(&self, artifact_path: &ArtifactPath) -> Option<&Artifact> {
+ pub fn get(&self, artifact_path: &ArtifactPath) -> Option<&ArtifactPath> {
self.store.get(artifact_path)
}
- pub(in crate::filestore) fn load_from_path(
+ pub(in crate::filestore) fn load_from_path<'a>(
&mut self,
- artifact_path: &ArtifactPath,
- ) -> Result<&Artifact> {
- if self.store.get(&artifact_path).is_some() {
- Err(anyhow!("Entry exists: {}", artifact_path.display()))
- } else {
- Ok(self
- .store
- .entry(artifact_path.clone())
- .or_insert(Artifact::load(&self.root, artifact_path.clone())?))
+ artifact_path: &'a ArtifactPath,
+ ) -> &'a ArtifactPath {
+ if !self.store.contains(artifact_path) {
+ self.store.insert(artifact_path.clone());
}
+ artifact_path
}
}