Skip to content

Commit

Permalink
fix: fix broken s3 paths on s3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulf Lilleengen committed Sep 20, 2023
1 parent faf4737 commit f9cb8b3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,12 @@ pub struct S3Path {
impl S3Path {
// Absolute path
pub fn from_path(path: &str) -> S3Path {
S3Path { path: path.to_string() }
let path = if path.starts_with('/') {
path.to_string()
} else {
format!("/{}", path)
};
S3Path { path }
}
// Relative to base
pub fn from_key(key: &str) -> S3Path {
Expand Down Expand Up @@ -654,4 +659,19 @@ mod tests {
assert_eq!(decoded.key(), "index");
assert_eq!(decoded.bucket(), "vexination");
}

#[test]
fn test_s3_path_keys() {
let p = S3Path::from_key("FOO");
assert_eq!(p.key(), "FOO");

let p = S3Path::from_path("/data/FOO");
assert_eq!(p.key(), "FOO");

let p = S3Path::from_path("data/FOO");
assert_eq!(p.key(), "FOO");

let p = S3Path::from_path("/data/foo/BAR");
assert_eq!(p.key(), "foo/BAR");
}
}

0 comments on commit f9cb8b3

Please sign in to comment.