From 16d2090becd22981997f62bd5dafac46049f6be9 Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Thu, 15 Sep 2022 16:26:43 -0400 Subject: [PATCH] fix edge case in output path generation --- Cargo.lock | 2 +- Cargo.toml | 2 +- config.toml.sample | 1 + src/main.rs | 35 +++++++++++++++++++++++++++++------ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b9c4351..405a49b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1332,7 +1332,7 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "registry-backup" -version = "0.4.0-rc.3" +version = "0.4.0-rc.4" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index e670426..fe9650a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "registry-backup" authors = ["Jonathan Strong "] -version = "0.4.0-rc.3" +version = "0.4.0-rc.4" edition = "2021" publish = ["shipyard-rs-public"] readme = "README.md" diff --git a/config.toml.sample b/config.toml.sample index 10241ae..75477e9 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -15,3 +15,4 @@ max-concurrent-requests = 50 [output] path = "output" overwrite-existing = false +format = "{crate}/{version}/download" diff --git a/src/main.rs b/src/main.rs index ed5857a..c911c30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,12 +86,14 @@ impl RegistryConfig { out = out.replace("{sha256-checksum}", cksum); out } else { - format!( - "{dl}/{name}/{version}/download", - dl = self.dl, - name = name, - version = version, - ) + Path::new(&self.dl) + .join(&format!( + "{name}/{version}/download", + name = name, + version = version, + )) + .display() + .to_string() } } } @@ -808,4 +810,25 @@ mod tests { assert_eq!(output_path, Path::new("output/lazy-static/x7b2z899"),); } + + #[test] + fn verify_blank_url_template_works_same_as_default() { + let c1 = RegistryConfig { + dl: "{crate}/{version}/download".to_string(), + api: String::new(), + allowed_registries: vec![], + auth_required: Some(true), + }; + let mut c2 = c1.clone(); + c2.dl = "".to_string(); + + assert_eq!( + c1.get_dl_url("lazy-static", "1.0.0", "x7b2z899"), + c2.get_dl_url("lazy-static", "1.0.0", "x7b2z899"), + ); + assert_eq!( + Path::new("output").join(c1.get_dl_url("lazy-static", "1.0.0", "x7b2z899")), + Path::new("output/lazy-static/1.0.0/download"), + ); + } }