summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/endpoint/configured.rs11
-rw-r--r--src/filestore/path.rs22
-rw-r--r--src/filestore/staging.rs2
-rw-r--r--src/filestore/util.rs17
4 files changed, 31 insertions, 21 deletions
diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs
index df2aa77..4b359ad 100644
--- a/src/endpoint/configured.rs
+++ b/src/endpoint/configured.rs
@@ -266,11 +266,14 @@ impl Endpoint {
.with_context(|| anyhow!("Collecting artifacts for copying to container {}", container_id))?;
let destination = PathBuf::from("/inputs/").join(artifact_file_name);
trace!("Copying {} to container: {}:{}", art.path().display(), container_id, destination.display());
- let buf = tokio::fs::read(staging.read().await.root_path().join(art.path()))
+ let buf = staging
+ .read()
.await
- .map(Vec::from)
- .with_context(|| anyhow!("Reading artifact {}, so it can be copied to container", art.path().display()))
- .map_err(Error::from)?;
+ .root_path()
+ .join(art.path())
+ .read()
+ .await
+ .with_context(|| anyhow!("Reading artifact {}, so it can be copied to container", art.path().display()))?;
let r = container.copy_file_into(&destination, &buf)
.await
diff --git a/src/filestore/path.rs b/src/filestore/path.rs
index 31e4bb0..0eba9ea 100644
--- a/src/filestore/path.rs
+++ b/src/filestore/path.rs
@@ -2,8 +2,10 @@ use std::path::Path;
use std::path::PathBuf;
use std::ffi::OsStr;
+use anyhow::anyhow;
use anyhow::Error;
use anyhow::Result;
+use anyhow::Context;
#[derive(Debug)]
pub struct StoreRoot(PathBuf);
@@ -41,7 +43,7 @@ impl AsRef<Path> for StoreRoot {
}
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct ArtifactPath(PathBuf);
impl ArtifactPath {
@@ -73,17 +75,15 @@ impl ArtifactPath {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FullArtifactPath(PathBuf);
-impl AsRef<Path> for FullArtifactPath {
- fn as_ref(&self) -> &Path {
- self.0.as_ref()
- }
-}
-
impl FullArtifactPath {
pub (in crate::filestore) fn is_dir(&self) -> bool {
self.0.is_dir()
}
+ pub (in crate::filestore) fn as_path(&self) -> &Path {
+ self.0.as_ref()
+ }
+
pub (in crate::filestore) fn is_file(&self) -> bool {
self.0.is_file()
}
@@ -91,5 +91,13 @@ impl FullArtifactPath {
pub fn display(&self) -> std::path::Display {
self.0.display()
}
+
+ pub async fn read(self) -> Result<Vec<u8>> {
+ tokio::fs::read(&self.0)
+ .await
+ .map(Vec::from)
+ .with_context(|| anyhow!("Reading artifact from path {}", self.0.display()))
+ .map_err(Error::from)
+ }
}
diff --git a/src/filestore/staging.rs b/src/filestore/staging.rs
index 86e22ae..0aca6da 100644
--- a/src/filestore/staging.rs
+++ b/src/filestore/staging.rs
@@ -72,7 +72,7 @@ impl StagingStore {
None
} else {
Some({
- self.0.load_from_path(fullpath.as_ref())
+ self.0.load_from_path(&fullpath)
.inspect(|r| trace!("Loaded from path {} = {:?}", fullpath.display(), r))
.with_context(|| anyhow!("Loading from path: {}", fullpath.display()))
.map_err(Error::from)
diff --git a/src/filestore/util.rs b/src/filestore/util.rs
index 4e0b85c..c32dd5d 100644
--- a/src/filestore/util.rs
+++ b/src/filestore/util.rs
@@ -3,7 +3,6 @@
use std::collections::BTreeMap;
use std::path::Path;
-use std::path::PathBuf;
use anyhow::Error;
use anyhow::Result;
@@ -24,7 +23,7 @@ use crate::filestore::path::*;
/// 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<PathBuf, Artifact>,
+ store: BTreeMap<ArtifactPath, Artifact>,
}
impl FileStoreImpl {
@@ -41,9 +40,9 @@ impl FileStoreImpl {
.and_then_ok(|f| {
progress.tick();
let p = root.stripped_from(f.path())?;
- Artifact::load(&root, p).map(|a| (f.path().to_path_buf(), a))
+ Artifact::load(&root, p.clone()).map(|a| (p, a))
})
- .collect::<Result<BTreeMap<PathBuf, Artifact>>>()?;
+ .collect::<Result<BTreeMap<ArtifactPath, Artifact>>>()?;
Ok(FileStoreImpl { root, store })
} else {
@@ -63,15 +62,15 @@ impl FileStoreImpl {
self.store.values()
}
- pub (in crate::filestore) fn load_from_path(&mut self, pb: &Path) -> Result<&Artifact> {
- if !self.is_sub_path(pb)? {
+ pub (in crate::filestore) fn load_from_path(&mut self, pb: &FullArtifactPath) -> Result<&Artifact> {
+ if !self.is_sub_path(pb.as_path())? {
Err(anyhow!("Not a sub-path of {}: {}", self.root.display(), pb.display()))
} else {
- if self.store.get(pb).is_some() {
+ let art_path = self.root.stripped_from(pb.as_path())?;
+ if self.store.get(&art_path).is_some() {
Err(anyhow!("Entry exists: {}", pb.display()))
} else {
- let p = self.root.stripped_from(pb)?;
- Ok(self.store.entry(pb.to_path_buf()).or_insert(Artifact::load(&self.root, p)?))
+ Ok(self.store.entry(art_path.clone()).or_insert(Artifact::load(&self.root, art_path)?))
}
}
}