!fixup 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.
This commit is contained in:
Daniel Karzel 2021-04-30 11:01:30 +10:00
parent b0ffeeab1d
commit 69f7565746
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
4 changed files with 43 additions and 27 deletions

View File

@ -10,11 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- An issue where both the ASB and the CLI point to the same default directory `xmr-btc-swap` for storing data. - 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. The asb now uses `xmr-btc-swap/asb` and the CLI `xmr-btc-swap/cli` as default directory.
This is a breaking change. 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. 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. 1. 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. 2. For the ASB you can change the data-dir in the config file of the ASB.
## [0.5.0] - 2021-04-17 ## [0.5.0] - 2021-04-17

View File

@ -1,10 +1,9 @@
use crate::fs::ensure_directory_exists; use crate::fs::{ensure_directory_exists, system_config_dir, system_data_dir};
use crate::tor::{DEFAULT_CONTROL_PORT, DEFAULT_SOCKS5_PORT}; use crate::tor::{DEFAULT_CONTROL_PORT, DEFAULT_SOCKS5_PORT};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use config::ConfigError; use config::ConfigError;
use dialoguer::theme::ColorfulTheme; use dialoguer::theme::ColorfulTheme;
use dialoguer::Input; use dialoguer::Input;
use directories_next::ProjectDirs;
use libp2p::core::Multiaddr; use libp2p::core::Multiaddr;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::ffi::OsStr; use std::ffi::OsStr;
@ -100,22 +99,21 @@ pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotIniti
Ok(Ok(file)) Ok(Ok(file))
} }
/// This is to store the configuration and seed files /// Default location for storing the config file for the ASB
// Linux: /home/<user>/.config/xmr-btc-swap/config.toml // Takes the default system config-dir and adds a `/asb/config.toml`
// OSX: /Users/<user>/Library/Preferences/xmr-btc-swap/config.toml
pub fn default_config_path() -> Result<PathBuf> { pub fn default_config_path() -> Result<PathBuf> {
ProjectDirs::from("", "", "xmr-btc-swap-asb") system_config_dir()
.map(|proj_dirs| proj_dirs.config_dir().to_path_buf()) .map(|dir| Path::join(&dir, "asb"))
.map(|dir| Path::join(&dir, "config.toml")) .map(|dir| Path::join(&dir, "config.toml"))
.context("Could not generate default configuration path") .context("Could not generate default config file path")
} }
/// This is the default location for storing data for the ASB /// Default location for storing data for the CLI
// Linux: /home/<user>/.local/share/xmr-btc-swap-asb/ // Takes the default system data-dir and adds a `/asb`
// OSX: /Users/<user>/Library/Application Support/xmr-btc-swap-asb/ fn default_data_dir() -> Result<PathBuf> {
fn asb_default_data_dir() -> Option<std::path::PathBuf> { system_data_dir()
ProjectDirs::from("", "", "xmr-btc-swap-asb") .map(|proj_dir| Path::join(&proj_dir, "asb"))
.map(|proj_dirs| proj_dirs.data_dir().to_path_buf()) .context("Could not generate default data dir")
} }
pub fn initial_setup<F>(config_path: PathBuf, config_file: F) -> Result<()> pub fn initial_setup<F>(config_path: PathBuf, config_file: F) -> Result<()>
@ -141,7 +139,7 @@ pub fn query_user_for_initial_testnet_config() -> Result<Config> {
let data_dir = Input::with_theme(&ColorfulTheme::default()) let data_dir = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Enter data directory for asb or hit return to use default") .with_prompt("Enter data directory for asb or hit return to use default")
.default( .default(
asb_default_data_dir() default_data_dir()
.context("No default data dir value for this system")? .context("No default data dir value for this system")?
.to_str() .to_str()
.context("Unsupported characters in default path")? .context("Unsupported characters in default path")?

View File

@ -1,8 +1,8 @@
use crate::fs::system_data_dir;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use directories_next::ProjectDirs;
use libp2p::core::Multiaddr; use libp2p::core::Multiaddr;
use libp2p::PeerId; use libp2p::PeerId;
use std::path::PathBuf; use std::path::{Path, PathBuf};
use std::str::FromStr; use std::str::FromStr;
use url::Url; use url::Url;
use uuid::Uuid; use uuid::Uuid;
@ -135,13 +135,12 @@ pub struct MoneroParams {
pub struct Data(pub PathBuf); pub struct Data(pub PathBuf);
/// Default location for storing data for the CLI /// Default location for storing data for the CLI
// Linux: /home/<user>/.local/share/xmr-btc-swap-cli/ // Takes the default system data-dir and adds a `/cli`
// OSX: /Users/<user>/Library/Application Support/xmr-btc-swap-cli/
impl Default for Data { impl Default for Data {
fn default() -> Self { fn default() -> Self {
Data( Data(
ProjectDirs::from("", "", "xmr-btc-swap-cli") system_data_dir()
.map(|proj_dirs| proj_dirs.data_dir().to_path_buf()) .map(|proj_dir| Path::join(&proj_dir, "cli"))
.expect("computed valid path for data dir"), .expect("computed valid path for data dir"),
) )
} }

View File

@ -1,5 +1,24 @@
use anyhow::Result; use anyhow::{Context, Result};
use std::path::Path; use directories_next::ProjectDirs;
use std::path::{Path, PathBuf};
/// This is the default location for the overall config-dir specific by system
// Linux: /home/<user>/.config/xmr-btc-swap/
// OSX: /Users/<user>/Library/Preferences/xmr-btc-swap/
pub fn system_config_dir() -> Result<PathBuf> {
ProjectDirs::from("", "", "xmr-btc-swap")
.map(|proj_dirs| proj_dirs.config_dir().to_path_buf())
.context("Could not generate default system configuration dir path")
}
/// This is the default location for the overall data-dir specific by system
// Linux: /home/<user>/.local/share/xmr-btc-swap/
// OSX: /Users/<user>/Library/ApplicationSupport/xmr-btc-swap/
pub fn system_data_dir() -> Result<PathBuf> {
ProjectDirs::from("", "", "xmr-btc-swap")
.map(|proj_dirs| proj_dirs.data_dir().to_path_buf())
.context("Could not generate default system data-dir dir path")
}
pub fn ensure_directory_exists(file: &Path) -> Result<(), std::io::Error> { pub fn ensure_directory_exists(file: &Path) -> Result<(), std::io::Error> {
if let Some(path) = file.parent() { if let Some(path) = file.parent() {