From 8a7c1300f1b80e073ddf1641a9eb155d7b593f6c Mon Sep 17 00:00:00 2001 From: pawan Date: Mon, 17 Aug 2020 17:18:44 +0530 Subject: [PATCH] Add migration code for restructure --- Cargo.lock | 1 + lighthouse/Cargo.toml | 1 + lighthouse/src/main.rs | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 9c9cc629973..d1608248702 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2890,6 +2890,7 @@ dependencies = [ "boot_node", "clap", "clap_utils", + "dirs", "env_logger", "environment", "eth2_testnet_config", diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index 44449ff8d50..3a002d7647e 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -32,6 +32,7 @@ account_manager = { "path" = "../account_manager" } clap_utils = { path = "../common/clap_utils" } eth2_testnet_config = { path = "../common/eth2_testnet_config" } lighthouse_version = { path = "../common/lighthouse_version" } +dirs = "2.0.2" [dev-dependencies] tempfile = "3.1.0" diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 2742f6c574b..f3bab4070d8 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -197,6 +197,25 @@ fn run( optional_testnet_config = clap_utils::parse_testnet_dir(matches, "testnet-dir")?; }; + // WARNING: Temporary migration code for directory restructure + // Remove after reasonably sure most users have migrated. + let default_dir = dirs::home_dir() + .map(|home| home.join(DEFAULT_DATA_DIR)) + .unwrap_or_else(|| PathBuf::from(".")); + let testnet_dir = default_dir.join(clap_utils::get_testnet_dir(matches)); + + if !matches.is_present("datadir") && !testnet_dir.exists() { + std::fs::create_dir_all(&testnet_dir) + .map_err(|e| format!("Failed to create testnet directory: {}", e))?; + for dir in ["validators", "wallets", "secrets", "beacon"].iter() { + let old_path = default_dir.join(dir); + if old_path.exists() { + std::fs::rename(old_path, testnet_dir.join(dir)) + .map_err(|e| format!("Failed to move directory: {}", e))?; + } + } + } + let builder = if let Some(log_path) = matches.value_of("logfile") { let path = log_path .parse::()