summaryrefslogtreecommitdiffstats
path: root/src/filestore/path.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-07 13:31:35 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-07 13:31:35 +0100
commit34ce17e2e90426acf6f5677da4ff1bec2288e98c (patch)
tree556609e3b0f10455c268a1f5fb07515639bc1a1e /src/filestore/path.rs
parent40f8002ea95659698cd328753ac7c98c79a8ba03 (diff)
Add runtime check in ArtifactPath::new
This adds a runtime check whether the artifact path is indeed relative. An absolute artifact path is a bug. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/filestore/path.rs')
-rw-r--r--src/filestore/path.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/filestore/path.rs b/src/filestore/path.rs
index fd79e1b..9a3e193 100644
--- a/src/filestore/path.rs
+++ b/src/filestore/path.rs
@@ -17,8 +17,8 @@ impl StoreRoot {
pub (in crate::filestore) fn stripped_from(&self, pb: &Path) -> Result<ArtifactPath> {
pb.strip_prefix(&self.0)
- .map(|p| ArtifactPath::new(p.to_path_buf()))
.map_err(Error::from)
+ .and_then(|p| ArtifactPath::new(p.to_path_buf()))
}
pub fn join<'a>(&'a self, ap: &'a ArtifactPath) -> FullArtifactPath<'a> {
@@ -49,8 +49,12 @@ impl AsRef<Path> for StoreRoot {
pub struct ArtifactPath(PathBuf);
impl ArtifactPath {
- pub (in crate::filestore) fn new(p: PathBuf) -> Self {
- ArtifactPath(p)
+ pub (in crate::filestore) fn new(p: PathBuf) -> Result<Self> {
+ if p.is_relative() {
+ Ok(ArtifactPath(p))
+ } else {
+ Err(anyhow!("Path is not relative: {}", p.display()))
+ }
}
pub fn display(&self) -> std::path::Display {