From 40510898a6cfe1d2acc4029d0524fff18ff9d0de Mon Sep 17 00:00:00 2001 From: tyshkor Date: Tue, 28 Jun 2022 10:34:09 +0200 Subject: [PATCH 1/4] delete dir, fn, change config default --- Cargo.lock | 12 +----------- forest/src/cli/config.rs | 10 ++++++++-- node/utils/Cargo.toml | 1 - node/utils/src/lib.rs | 10 ---------- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7301461d10d5..294f66d35330 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2070,15 +2070,6 @@ dependencies = [ "dirs-sys", ] -[[package]] -name = "dirs" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ - "dirs-sys", -] - [[package]] name = "dirs-sys" version = "0.3.7" @@ -7186,7 +7177,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1785ab2a8accec77189e23fead221f2543cebf7ccf569788511cdac9f5fad168" dependencies = [ - "dirs 2.0.2", + "dirs", "hex", "lazy_static", "log", @@ -8877,7 +8868,6 @@ checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" name = "utils" version = "0.1.0" dependencies = [ - "dirs 4.0.0", "libc", "log", "serde", diff --git a/forest/src/cli/config.rs b/forest/src/cli/config.rs index 49d0005e32ce..d8284c9d17f9 100644 --- a/forest/src/cli/config.rs +++ b/forest/src/cli/config.rs @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0, MIT use chain_sync::SyncConfig; +use directories::ProjectDirs; use forest_libp2p::Libp2pConfig; use networks::ChainConfig; use rpc_client::DEFAULT_PORT; use serde::{Deserialize, Serialize}; -use utils::get_home_dir; #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(default)] @@ -34,9 +34,15 @@ pub struct Config { impl Default for Config { fn default() -> Self { + let dir = ProjectDirs::from("com", "ChainSafe", "Forest").expect("project directories couldn't be found and that FOREST_CONFIG_PATH must be set manually."); Self { network: Libp2pConfig::default(), - data_dir: get_home_dir() + "/.forest", + data_dir: dir + .data_dir() + .to_path_buf() + .into_os_string() + .into_string() + .unwrap(), genesis_file: None, enable_rpc: true, rpc_port: DEFAULT_PORT, diff --git a/node/utils/Cargo.toml b/node/utils/Cargo.toml index edf44af69a28..34f101654e73 100644 --- a/node/utils/Cargo.toml +++ b/node/utils/Cargo.toml @@ -5,7 +5,6 @@ authors = ["ChainSafe Systems "] edition = "2021" [dependencies] -dirs = "4.0" toml = "0.5" libc = "0.2" serde = "1.0" diff --git a/node/utils/src/lib.rs b/node/utils/src/lib.rs index 5003653e20c5..d8339a9ac443 100644 --- a/node/utils/src/lib.rs +++ b/node/utils/src/lib.rs @@ -1,7 +1,6 @@ // Copyright 2019-2022 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use dirs::home_dir; use std::fs::{create_dir_all, File}; use std::io::{prelude::*, Result}; use std::path::Path; @@ -47,15 +46,6 @@ pub fn read_file_to_string(path: &Path) -> Result { Ok(string) } -/// Gets the home directory of the current system. -/// Will return correct path for windows, linux, and osx. -/// -/// # Panics -/// We will panic if we cannot determine a home directory. -pub fn get_home_dir() -> String { - home_dir().unwrap().to_str().unwrap().to_owned() -} - /// Converts a toml file represented as a string to `S` /// /// # Example From 39c0502dc29d6d57311fcf4612c8d088c9d26269 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Tue, 28 Jun 2022 10:38:49 +0200 Subject: [PATCH 2/4] error msg --- forest/src/cli/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forest/src/cli/config.rs b/forest/src/cli/config.rs index d8284c9d17f9..0a908d93ff52 100644 --- a/forest/src/cli/config.rs +++ b/forest/src/cli/config.rs @@ -34,7 +34,7 @@ pub struct Config { impl Default for Config { fn default() -> Self { - let dir = ProjectDirs::from("com", "ChainSafe", "Forest").expect("project directories couldn't be found and that FOREST_CONFIG_PATH must be set manually."); + let dir = ProjectDirs::from("com", "ChainSafe", "Forest").expect("failed to find project directories, please set FOREST_CONFIG_PATH environment variable manually."); Self { network: Libp2pConfig::default(), data_dir: dir From 3abe77215d91f7654b497c3cb85e30d21c3e47c5 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Wed, 29 Jun 2022 10:22:13 +0200 Subject: [PATCH 3/4] fix pathbuf --- forest/src/cli/config.rs | 10 +++------- forest/src/daemon.rs | 3 ++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/forest/src/cli/config.rs b/forest/src/cli/config.rs index 0a908d93ff52..886a3035259b 100644 --- a/forest/src/cli/config.rs +++ b/forest/src/cli/config.rs @@ -7,11 +7,12 @@ use forest_libp2p::Libp2pConfig; use networks::ChainConfig; use rpc_client::DEFAULT_PORT; use serde::{Deserialize, Serialize}; +use std::path::PathBuf; #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(default)] pub struct Config { - pub data_dir: String, + pub data_dir: PathBuf, pub genesis_file: Option, pub enable_rpc: bool, pub rpc_port: u16, @@ -37,12 +38,7 @@ impl Default for Config { let dir = ProjectDirs::from("com", "ChainSafe", "Forest").expect("failed to find project directories, please set FOREST_CONFIG_PATH environment variable manually."); Self { network: Libp2pConfig::default(), - data_dir: dir - .data_dir() - .to_path_buf() - .into_os_string() - .into_string() - .unwrap(), + data_dir: dir.data_dir().to_path_buf(), genesis_file: None, enable_rpc: true, rpc_port: DEFAULT_PORT, diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index 241971b411dd..f9e64c3c06cc 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -39,7 +39,8 @@ pub(super) async fn start(config: Config) { option_env!("FOREST_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")) ); - let path: PathBuf = [&config.data_dir, "libp2p"].iter().collect(); + let mut path: PathBuf = config.data_dir.clone(); + path.push("libp2p"); let net_keypair = get_keypair(&path.join("keypair")).unwrap_or_else(|| { // Keypair not found, generate and save generated keypair let gen_keypair = ed25519::Keypair::generate(); From cdc28f56025f382e723c92b2906efda9cecb9e49 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Thu, 30 Jun 2022 13:47:08 +0200 Subject: [PATCH 4/4] fix --- forest/src/daemon.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index f9e64c3c06cc..cad0f8cca3d7 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -39,8 +39,7 @@ pub(super) async fn start(config: Config) { option_env!("FOREST_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")) ); - let mut path: PathBuf = config.data_dir.clone(); - path.push("libp2p"); + let path: PathBuf = config.data_dir.join("libp2p"); let net_keypair = get_keypair(&path.join("keypair")).unwrap_or_else(|| { // Keypair not found, generate and save generated keypair let gen_keypair = ed25519::Keypair::generate();