From b0ffeeab1d7033dd8a236a5e0a16258d8eb56719 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Thu, 29 Apr 2021 18:50:49 +1000 Subject: [PATCH] Different default directories for CLI and ASB Using the same default directory as data-/config-dir has caused unwanted side effects when running both applications on the same machine. Use these directory names: - ASB: xmr-btc-swap-asb - CLI: xmr-btc-swap-cli Since the functionality is now application specific the respective functions were moved into the appropriate module of the application. --- CHANGELOG.md | 9 +++++++++ swap/src/asb/config.rs | 23 +++++++++++++++++++++-- swap/src/bin/asb.rs | 4 ++-- swap/src/cli/command.rs | 11 +++++++++-- swap/src/fs.rs | 25 ++----------------------- 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef66b99a..20c99674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- An issue where both the ASB and the CLI point to the same default directory `xmr-btc-swap` for storing data. + The asb now uses `xmr-btc-swap-asb` and the CLI `xmr-btc-swap-cli` as default directory. + This is a breaking change. + If you want to access data created by a previous version you will have to rename the data folder or one of the following. + For the CLI you can use `--data-dir` to point to the old directory. + For the ASB you can change the data-dir in the config file of the ASB. + ## [0.5.0] - 2021-04-17 ### Changed diff --git a/swap/src/asb/config.rs b/swap/src/asb/config.rs index 5c720988..51a9d08c 100644 --- a/swap/src/asb/config.rs +++ b/swap/src/asb/config.rs @@ -1,9 +1,10 @@ -use crate::fs::{default_data_dir, ensure_directory_exists}; +use crate::fs::ensure_directory_exists; use crate::tor::{DEFAULT_CONTROL_PORT, DEFAULT_SOCKS5_PORT}; use anyhow::{Context, Result}; use config::ConfigError; use dialoguer::theme::ColorfulTheme; use dialoguer::Input; +use directories_next::ProjectDirs; use libp2p::core::Multiaddr; use serde::{Deserialize, Serialize}; use std::ffi::OsStr; @@ -99,6 +100,24 @@ pub fn read_config(config_path: PathBuf) -> Result/.config/xmr-btc-swap/config.toml +// OSX: /Users//Library/Preferences/xmr-btc-swap/config.toml +pub fn default_config_path() -> Result { + ProjectDirs::from("", "", "xmr-btc-swap-asb") + .map(|proj_dirs| proj_dirs.config_dir().to_path_buf()) + .map(|dir| Path::join(&dir, "config.toml")) + .context("Could not generate default configuration path") +} + +/// This is the default location for storing data for the ASB +// Linux: /home//.local/share/xmr-btc-swap-asb/ +// OSX: /Users//Library/Application Support/xmr-btc-swap-asb/ +fn asb_default_data_dir() -> Option { + ProjectDirs::from("", "", "xmr-btc-swap-asb") + .map(|proj_dirs| proj_dirs.data_dir().to_path_buf()) +} + pub fn initial_setup(config_path: PathBuf, config_file: F) -> Result<()> where F: Fn() -> Result, @@ -122,7 +141,7 @@ pub fn query_user_for_initial_testnet_config() -> Result { let data_dir = Input::with_theme(&ColorfulTheme::default()) .with_prompt("Enter data directory for asb or hit return to use default") .default( - default_data_dir() + asb_default_data_dir() .context("No default data dir value for this system")? .to_str() .context("Unsupported characters in default path")? diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index e2aea45f..663cf266 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -22,11 +22,11 @@ use std::sync::Arc; use structopt::StructOpt; use swap::asb::command::{Arguments, Command}; use swap::asb::config::{ - initial_setup, query_user_for_initial_testnet_config, read_config, Config, ConfigNotInitialized, + default_config_path, initial_setup, query_user_for_initial_testnet_config, read_config, Config, + ConfigNotInitialized, }; use swap::database::Database; use swap::env::GetConfig; -use swap::fs::default_config_path; use swap::monero::Amount; use swap::network::swarm; use swap::protocol::alice::event_loop::KrakenRate; diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index 90db2c3c..51f0dfe7 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -1,5 +1,5 @@ -use crate::fs::default_data_dir; use anyhow::{Context, Result}; +use directories_next::ProjectDirs; use libp2p::core::Multiaddr; use libp2p::PeerId; use std::path::PathBuf; @@ -134,9 +134,16 @@ pub struct MoneroParams { #[derive(Clone, Debug)] pub struct Data(pub PathBuf); +/// Default location for storing data for the CLI +// Linux: /home//.local/share/xmr-btc-swap-cli/ +// OSX: /Users//Library/Application Support/xmr-btc-swap-cli/ impl Default for Data { fn default() -> Self { - Data(default_data_dir().expect("computed valid path for data dir")) + Data( + ProjectDirs::from("", "", "xmr-btc-swap-cli") + .map(|proj_dirs| proj_dirs.data_dir().to_path_buf()) + .expect("computed valid path for data dir"), + ) } } diff --git a/swap/src/fs.rs b/swap/src/fs.rs index 38be1bca..038c2913 100644 --- a/swap/src/fs.rs +++ b/swap/src/fs.rs @@ -1,26 +1,5 @@ -use anyhow::{Context, Result}; -use directories_next::ProjectDirs; -use std::path::{Path, PathBuf}; - -/// This is to store the configuration and seed files -// Linux: /home//.config/xmr-btc-swap/ -// OSX: /Users//Library/Preferences/xmr-btc-swap/ -fn default_config_dir() -> Option { - ProjectDirs::from("", "", "xmr-btc-swap").map(|proj_dirs| proj_dirs.config_dir().to_path_buf()) -} - -pub fn default_config_path() -> Result { - default_config_dir() - .map(|dir| Path::join(&dir, "config.toml")) - .context("Could not generate default configuration path") -} - -/// This is to store the DB -// Linux: /home//.local/share/xmr-btc-swap/ -// OSX: /Users//Library/Application Support/xmr-btc-swap/ -pub fn default_data_dir() -> Option { - ProjectDirs::from("", "", "xmr-btc-swap").map(|proj_dirs| proj_dirs.data_dir().to_path_buf()) -} +use anyhow::Result; +use std::path::Path; pub fn ensure_directory_exists(file: &Path) -> Result<(), std::io::Error> { if let Some(path) = file.parent() {