commit e75124ed7f9071d17f206afc5848de8a495b9db4
parent 62a014659d8475eda13bc1d5e1481da42a1c94bf
Author: Gavin Peacock <gpeacock@adobe.com>
Date: Thu, 23 Feb 2023 16:33:43 -0800
Fixed unit test failure (invalid unique name generation). (#190)
* Fix generation of unique filenames
Diffstat:
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/sdk/src/manifest_store.rs b/sdk/src/manifest_store.rs
@@ -412,7 +412,7 @@ mod tests {
fn manifest_report_from_file_with_resources() {
let manifest_store = ManifestStore::from_file_with_resources(
"tests/fixtures/CIE-sig-CA.jpg",
- "../target/tmp/ms",
+ "../target/ms",
)
.expect("from_store_with_resources");
println!("{manifest_store}");
diff --git a/sdk/src/resource_store.rs b/sdk/src/resource_store.rs
@@ -78,13 +78,16 @@ impl ResourceStore {
_ => "",
};
// clean string for possible filesystem use
- let mut id = key.replace(['/', ':'], "-") + ext;
+ let id_base = key.replace(['/', ':'], "-");
// ensure it is unique in this store
- let count = 1;
+ let mut count = 1;
+ let mut id = format!("{id_base}{ext}");
while self.exists(&id) {
- id = format!("{id}-{count}{ext}");
+ id = format!("{id_base}-{count}{ext}");
+ count += 1;
}
+ dbg!(&id);
id
}
@@ -109,7 +112,9 @@ impl ResourceStore {
#[cfg(feature = "file_io")]
if let Some(base) = self.base_path.as_ref() {
let path = base.join(id.into());
- std::fs::write(path, value.into())?;
+ std::fs::create_dir_all(path.parent().unwrap_or(Path::new("")))?;
+ #[allow(clippy::expect_used)]
+ std::fs::write(path, value.into()).expect("write failed");
return Ok(());
}
self.resources.insert(id.into(), value.into());