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. 35
      src/main.rs

2
Cargo.lock generated

@ -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",

2
Cargo.toml

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

1
config.toml.sample

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

35
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"),
);
}
}

Loading…
Cancel
Save