Browse Source

fix edge case in output path generation

master
Jonathan Strong 2 years ago
parent
commit
16d2090bec
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 1
      config.toml.sample
  4. 31
      src/main.rs

2
Cargo.lock generated

@ -1332,7 +1332,7 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]] [[package]]
name = "registry-backup" name = "registry-backup"
version = "0.4.0-rc.3" version = "0.4.0-rc.4"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",

2
Cargo.toml

@ -1,7 +1,7 @@
[package] [package]
name = "registry-backup" name = "registry-backup"
authors = ["Jonathan Strong <jstrong@shipyard.rs>"] authors = ["Jonathan Strong <jstrong@shipyard.rs>"]
version = "0.4.0-rc.3" version = "0.4.0-rc.4"
edition = "2021" edition = "2021"
publish = ["shipyard-rs-public"] publish = ["shipyard-rs-public"]
readme = "README.md" readme = "README.md"

1
config.toml.sample

@ -15,3 +15,4 @@ max-concurrent-requests = 50
[output] [output]
path = "output" path = "output"
overwrite-existing = false overwrite-existing = false
format = "{crate}/{version}/download"

31
src/main.rs

@ -86,12 +86,14 @@ impl RegistryConfig {
out = out.replace("{sha256-checksum}", cksum); out = out.replace("{sha256-checksum}", cksum);
out out
} else { } else {
format!( Path::new(&self.dl)
"{dl}/{name}/{version}/download", .join(&format!(
dl = self.dl, "{name}/{version}/download",
name = name, name = name,
version = version, version = version,
) ))
.display()
.to_string()
} }
} }
} }
@ -808,4 +810,25 @@ mod tests {
assert_eq!(output_path, Path::new("output/lazy-static/x7b2z899"),); 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"),
);
}
} }

Loading…
Cancel
Save