ソースを参照

dakirc+tau: do not create_dir_all on replay path if not needed

dasman 2 年 前
コミット
cfe9f49de2

+ 5 - 7
bin/darkirc/src/main.rs

@@ -94,6 +94,10 @@ struct Args {
     /// Replay logs (DB) path
     replay_datastore: String,
 
+    /// Flag to store Sled DB instructions
+    #[structopt(long)]
+    replay_mode: bool,
+
     /// Generate a new NaCl keypair and exit
     #[structopt(long)]
     gen_chacha_keypair: bool,
@@ -126,10 +130,6 @@ struct Args {
     #[structopt(long)]
     encrypt_password: bool,
 
-    /// replay_mode
-    #[structopt(long)]
-    replay_mode: bool,
-
     /// P2P network settings
     #[structopt(flatten)]
     net: SettingsOpt,
@@ -235,8 +235,6 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
         return Ok(())
     }
 
-    let replay_mode = args.replay_mode;
-
     info!("Initializing DarkIRC node");
 
     // Create datastore path if not there already.
@@ -244,7 +242,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
     fs::create_dir_all(&datastore).await?;
 
     let replay_datastore = expand_path(&args.replay_datastore)?;
-    fs::create_dir_all(&replay_datastore).await?;
+    let replay_mode = args.replay_mode;
 
     info!("Instantiating event DAG");
     let sled_db = sled::open(datastore)?;

+ 2 - 4
bin/genev/genevd/src/main.rs

@@ -60,11 +60,11 @@ struct Args {
     #[structopt(long, default_value = "~/.local/darkfi/genev_db")]
     pub datastore: String,
 
-    #[structopt(short, long, default_value = "~/.local/darkfi/replayed_genev_db")]
     /// Replay logs (DB) path
+    #[structopt(short, long, default_value = "~/.local/darkfi/replayed_genev_db")]
     replay_datastore: String,
 
-    /// replay_mode
+    /// Flag to store Sled DB instructions
     #[structopt(long)]
     replay_mode: bool,
 
@@ -113,8 +113,6 @@ async fn realmain(settings: Args, executor: Arc<smol::Executor<'static>>) -> Res
     fs::create_dir_all(&datastore_path).await?;
 
     let replay_datastore = expand_path(&settings.replay_datastore)?;
-    fs::create_dir_all(&replay_datastore).await?;
-
     let replay_mode = settings.replay_mode;
 
     let sled_db = sled::open(datastore_path.clone())?;

+ 0 - 2
bin/tau/taud/src/main.rs

@@ -353,8 +353,6 @@ async fn realmain(settings: Args, executor: Arc<smol::Executor<'static>>) -> Res
     fs::create_dir_all(&datastore).await?;
 
     let replay_datastore = expand_path(&settings.replay_datastore)?;
-    fs::create_dir_all(&replay_datastore).await?;
-
     let replay_mode = settings.replay_mode;
 
     info!("Instantiating event DAG");

+ 2 - 2
bin/tau/taud/src/settings.rs

@@ -42,11 +42,11 @@ pub struct Args {
     #[structopt(long, default_value = "~/.local/darkfi/taud_db")]
     pub datastore: String,
 
-    #[structopt(long, default_value = "~/.local/darkfi/replayed_taud_db")]
     /// Replay logs (DB) path
+    #[structopt(long, default_value = "~/.local/darkfi/replayed_taud_db")]
     pub replay_datastore: String,
 
-    /// replay_mode
+    /// Flag to store Sled DB instructions
     #[structopt(long)]
     pub replay_mode: bool,
 

+ 2 - 1
src/event_graph/util.rs

@@ -18,7 +18,7 @@
 
 use std::{
     collections::HashMap,
-    fs::{File, OpenOptions},
+    fs::{self, File, OpenOptions},
     io::Write,
     path::Path,
     time::UNIX_EPOCH,
@@ -133,6 +133,7 @@ pub(super) fn generate_genesis(days_rotation: u64) -> Event {
 }
 
 pub(super) fn replayer_log(datastore: &Path, cmd: String, value: Vec<u8>) -> Result<()> {
+    fs::create_dir_all(datastore)?;
     let datastore = datastore.join("replayer.log");
     if !datastore.exists() {
         File::create(&datastore)?;