summaryrefslogtreecommitdiffstats
path: root/src/filestore
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-02-17 09:48:07 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-02-17 09:59:34 +0100
commit6b2e73a9cf24c80b3b86df68ff62392fdfc1e09c (patch)
tree4a448aadc8ba97f94fec1b877c050f987a89c32d /src/filestore
parent04e7602e34987b832e1d2e95405f61443b30a641 (diff)
Pass MergedStores to endpoint/jobs rather than only staging store
This patch changes the code so that the MergedStores object is known in the endpoints and job execution code. This is necessary, because the jobs must be able to load artifacts from the release store as well, for example if a library was released in another submit and we can reuse it because the script for that library didn't change. For that, the interface of StoreRoot::join() was changed - -> Result<FullArtifactPath<'a>> + -> Result<Option<FullArtifactPath<'a>>> whereas it returns an Ok(None) if the artifact requested does not exist. This was necessary to try-joining a path on the store root of the staging store, and if there is no such file continue with try-joining the path on the release store. The calling code got a bit more complex with that change, though. Next, the MergedStores got a `derive(Clone)` because clone()ing it is cheap (two `Arc`s) and necessary to pass it easily to the jobs. Each instance of the code where the staging store was consulted was changed to consult the the release store as well. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/filestore')
-rw-r--r--src/filestore/merged.rs15
-rw-r--r--src/filestore/path.rs6
2 files changed, 14 insertions, 7 deletions
diff --git a/src/filestore/merged.rs b/src/filestore/merged.rs
index 7363eb2..1503870 100644
--- a/src/filestore/merged.rs
+++ b/src/filestore/merged.rs
@@ -12,16 +12,17 @@
// the rewrite
#![allow(unused)]
-
use std::sync::Arc;
use std::path::Path;
+use anyhow::anyhow;
use anyhow::Result;
use getset::Getters;
use log::trace;
use tokio::sync::RwLock;
use crate::filestore::path::ArtifactPath;
+use crate::filestore::path::FullArtifactPath;
use crate::filestore::ReleaseStore;
use crate::filestore::StagingStore;
@@ -31,7 +32,7 @@ use crate::filestore::StagingStore;
/// The stores are not actually merged (on disk or in memory), but the querying mechanism works in
/// a way where it _always_ preferes the staging store over the release store.
///
-#[derive(Getters)]
+#[derive(Clone, Getters)]
pub struct MergedStores {
#[getset(get = "pub")]
release: Arc<RwLock<ReleaseStore>>,
@@ -50,7 +51,10 @@ impl MergedStores {
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)?;
+ let staging_path = staging
+ .root_path()
+ .join(&artifact_path)?
+ .ok_or_else(|| anyhow!("Does not exist in staging store: {:?}", artifact_path))?;
trace!("staging_path = {:?}", staging_path.display());
if staging_path.exists() {
@@ -65,7 +69,9 @@ impl MergedStores {
}
let release = &mut self.release.write().await.0;
- let release_path = release.root_path().join(&artifact_path)?;
+ let release_path = release.root_path()
+ .join(&artifact_path)?
+ .ok_or_else(|| anyhow!("Not found in release store: {:?}", artifact_path))?;
trace!("release_path = {:?}", release_path);
if release_path.exists() {
@@ -88,4 +94,5 @@ impl MergedStores {
self.release.read().await.get(p).cloned()
}
+
}
diff --git a/src/filestore/path.rs b/src/filestore/path.rs
index 486532f..19016bd 100644
--- a/src/filestore/path.rs
+++ b/src/filestore/path.rs
@@ -44,15 +44,15 @@ impl StoreRoot {
}
}
- pub fn join<'a>(&'a self, ap: &'a ArtifactPath) -> Result<FullArtifactPath<'a>> {
+ pub fn join<'a>(&'a self, ap: &'a ArtifactPath) -> Result<Option<FullArtifactPath<'a>>> {
let join = self.0.join(&ap.0);
if join.is_file() {
- Ok(FullArtifactPath(&self, ap))
+ Ok(Some(FullArtifactPath(&self, ap)))
} else if join.is_dir() {
Err(anyhow!("Cannot load non-file path: {}", join.display()))
} else {
- Err(anyhow!("Path does not exist: {}", join.display()))
+ Ok(None)
}
}