Skip to content

Commit

Permalink
create cache directory if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangZhuoSJTU committed Jun 26, 2024
1 parent 1f442fe commit bc5d1e4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/block-explorers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,13 @@ impl Cache {
}

fn set<T: Serialize>(&self, prefix: &str, address: Address, item: T) {
let path = self.root.join(prefix).join(format!("{address:?}.json"));
// Create the cache directory if it does not exist.
let path = self.root.join(prefix);
if std::fs::create_dir_all(&path).is_err() {
return;
}

let path = path.join(format!("{address:?}.json"));
let writer = std::fs::File::create(path).ok().map(std::io::BufWriter::new);
if let Some(mut writer) = writer {
let _ = serde_json::to_writer(
Expand Down

0 comments on commit bc5d1e4

Please sign in to comment.