Skip to content

Commit

Permalink
Create cache directories if they do not already exist (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
intoverflow authored Apr 1, 2024
1 parent a919671 commit 2a4dbd5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
5 changes: 3 additions & 2 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ pub fn save_receipt<T: serde::Serialize>(receipt_label: &String, receipt_data: &
}

fn zkp_cache_path(receipt_label: &String) -> String {
Path::new("cache_zkp")
.join(format!("{}.zkp", receipt_label))
let dir = Path::new("cache_zkp");
std::fs::create_dir_all(&dir).expect("Could not create directory");
dir.join(format!("{}.zkp", receipt_label))
.to_str()
.unwrap()
.to_string()
Expand Down
7 changes: 3 additions & 4 deletions lib/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ pub mod rpc_db;
pub mod verify;

pub fn cache_file_path(cache_path: &Path, network: &str, block_no: u64, ext: &str) -> PathBuf {
cache_path
.join(network)
.join(block_no.to_string())
.with_extension(ext)
let dir = cache_path.join(network);
std::fs::create_dir_all(&dir).expect("Could not create directory");
dir.join(block_no.to_string()).with_extension(ext)
}

#[derive(Clone)]
Expand Down
14 changes: 5 additions & 9 deletions lib/src/host/rpc_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::path::{Path, PathBuf};
use std::path::PathBuf;

use anyhow::Context;
use zeth_primitives::{
Expand All @@ -22,21 +22,17 @@ use zeth_primitives::{
};

use crate::{
host::provider::{new_provider, BlockQuery},
host::{
cache_file_path,
provider::{new_provider, BlockQuery},
},
optimism::{
batcher_db::{BatcherDb, BlockInput, MemDb},
config::ChainConfig,
deposits, system_config,
},
};

fn cache_file_path(cache_path: &Path, network: &str, block_no: u64, ext: &str) -> PathBuf {
cache_path
.join(network)
.join(block_no.to_string())
.with_extension(ext)
}

fn eth_cache_path(cache: &Option<PathBuf>, block_no: u64) -> Option<PathBuf> {
cache
.as_ref()
Expand Down

0 comments on commit 2a4dbd5

Please sign in to comment.