Skip to content

Commit 1968128

Browse files
Create cache directory if needed (#52)
#51
1 parent 1f442fe commit 1968128

File tree

1 file changed

+7
-1
lines changed
  • crates/block-explorers/src

1 file changed

+7
-1
lines changed

crates/block-explorers/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,13 @@ impl Cache {
438438
}
439439

440440
fn set<T: Serialize>(&self, prefix: &str, address: Address, item: T) {
441-
let path = self.root.join(prefix).join(format!("{address:?}.json"));
441+
// Create the cache directory if it does not exist.
442+
let path = self.root.join(prefix);
443+
if std::fs::create_dir_all(&path).is_err() {
444+
return;
445+
}
446+
447+
let path = path.join(format!("{address:?}.json"));
442448
let writer = std::fs::File::create(path).ok().map(std::io::BufWriter::new);
443449
if let Some(mut writer) = writer {
444450
let _ = serde_json::to_writer(

0 commit comments

Comments
 (0)