diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-07 13:31:35 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-07 13:31:35 +0100 |
commit | 34ce17e2e90426acf6f5677da4ff1bec2288e98c (patch) | |
tree | 556609e3b0f10455c268a1f5fb07515639bc1a1e /src/filestore/path.rs | |
parent | 40f8002ea95659698cd328753ac7c98c79a8ba03 (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.rs | 10 |
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 { |