460: Different default directories for CLI and ASB r=da-kami a=da-kami

Fixes #437 

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.

Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
bors[bot] 2021-04-30 04:24:29 +00:00 committed by GitHub
commit cf1c448b7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 19 deletions

View File

@ -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:
1. For the CLI you can use `--data-dir` to point to the old directory.
2. For the ASB you can change the data-dir in the config file of the ASB.
## [0.5.0] - 2021-04-17
### Changed

View File

@ -1,4 +1,4 @@
use crate::fs::{default_data_dir, 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 anyhow::{Context, Result};
use config::ConfigError;
@ -99,6 +99,23 @@ pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotIniti
Ok(Ok(file))
}
/// Default location for storing the config file for the ASB
// Takes the default system config-dir and adds a `/asb/config.toml`
pub fn default_config_path() -> Result<PathBuf> {
system_config_dir()
.map(|dir| Path::join(&dir, "asb"))
.map(|dir| Path::join(&dir, "config.toml"))
.context("Could not generate default config file path")
}
/// Default location for storing data for the CLI
// Takes the default system data-dir and adds a `/asb`
fn default_data_dir() -> Result<PathBuf> {
system_data_dir()
.map(|proj_dir| Path::join(&proj_dir, "asb"))
.context("Could not generate default data dir")
}
pub fn initial_setup<F>(config_path: PathBuf, config_file: F) -> Result<()>
where
F: Fn() -> Result<Config>,

View File

@ -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;

View File

@ -1,8 +1,8 @@
use crate::fs::default_data_dir;
use crate::fs::system_data_dir;
use anyhow::{Context, Result};
use libp2p::core::Multiaddr;
use libp2p::PeerId;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use url::Url;
use uuid::Uuid;
@ -134,9 +134,15 @@ pub struct MoneroParams {
#[derive(Clone, Debug)]
pub struct Data(pub PathBuf);
/// Default location for storing data for the CLI
// Takes the default system data-dir and adds a `/cli`
impl Default for Data {
fn default() -> Self {
Data(default_data_dir().expect("computed valid path for data dir"))
Data(
system_data_dir()
.map(|proj_dir| Path::join(&proj_dir, "cli"))
.expect("computed valid path for data dir"),
)
}
}

View File

@ -2,24 +2,22 @@ use anyhow::{Context, Result};
use directories_next::ProjectDirs;
use std::path::{Path, PathBuf};
/// This is to store the configuration and seed files
/// 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/
fn default_config_dir() -> Option<PathBuf> {
ProjectDirs::from("", "", "xmr-btc-swap").map(|proj_dirs| proj_dirs.config_dir().to_path_buf())
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")
}
pub fn default_config_path() -> Result<PathBuf> {
default_config_dir()
.map(|dir| Path::join(&dir, "config.toml"))
.context("Could not generate default configuration path")
}
/// This is to store the DB
/// 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 default_data_dir() -> Option<std::path::PathBuf> {
ProjectDirs::from("", "", "xmr-btc-swap").map(|proj_dirs| proj_dirs.data_dir().to_path_buf())
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> {