Remove dependency from arti-client to tor-config.

I'm about to make tor-config a higher-level module, so it can't be a
dependency for tor-config.
This commit is contained in:
Nick Mathewson 2021-11-16 16:01:55 -05:00
parent 727e420d5c
commit e5c5519f7b
4 changed files with 16 additions and 10 deletions

2
Cargo.lock generated
View File

@ -98,6 +98,7 @@ version = "0.0.1"
dependencies = [
"anyhow",
"derive_builder",
"directories",
"futures",
"hyper",
"pin-project",
@ -107,7 +108,6 @@ dependencies = [
"tokio-util",
"tor-chanmgr",
"tor-circmgr",
"tor-config",
"tor-dirmgr",
"tor-persist",
"tor-proto",

View File

@ -25,13 +25,13 @@ experimental-api = []
[dependencies]
tor-circmgr = { path="../tor-circmgr", version = "0.0.1"}
tor-chanmgr = { path="../tor-chanmgr", version = "0.0.1"}
tor-config = { path="../tor-config", version = "0.0.1"}
tor-dirmgr = { path="../tor-dirmgr", version = "0.0.1"}
tor-persist = { path="../tor-persist", version = "0.0.1"}
tor-proto = { path="../tor-proto", version = "0.0.1"}
tor-rtcompat = { path="../tor-rtcompat", version = "0.0.1"}
derive_builder = "0.10.2"
directories = "4.0.1"
futures = "0.3.13"
tracing = "0.1.26"
serde = { version = "1.0.124", features = ["derive"] }

View File

@ -94,19 +94,23 @@ pub struct TorClientConfig {
impl TorClientConfig {
/// Returns a `TorClientConfig` using reasonably sane defaults.
///
/// This uses `tor_config`'s definitions for `APP_LOCAL_DATA` and
/// `APP_CACHE` for the state and cache directories respectively.
/// This gies the same result as using `tor_config`'s definitions
/// for `APP_LOCAL_DATA` and `APP_CACHE` for the state and cache
/// directories respectively.
///
/// (On unix, this usually works out to `~/.local/share/arti` and
/// `~/.cache/arti`, depending on your environment. We use the
/// `directories` crate for reasonable defaults on other platforms.)
pub fn sane_defaults() -> Result<Self> {
let state_dir = tor_config::CfgPath::new("${APP_LOCAL_DATA}".into())
.path()
.map_err(|e| Error::Configuration(format!("failed to find APP_LOCAL_DATA: {:?}", e)))?;
let cache_dir = tor_config::CfgPath::new("${APP_CACHE}".into())
.path()
.map_err(|e| Error::Configuration(format!("failed to find APP_CACHE: {:?}", e)))?;
// Note: this must stay in sync with project_dirs() in the
// tor-config crate.
let dirs =
directories::ProjectDirs::from("org", "torproject", "Arti").ok_or_else(|| {
Error::Configuration("Could not determine default directories".to_string())
})?;
let state_dir = dirs.data_local_dir();
let cache_dir = dirs.cache_dir();
Self::with_directories(state_dir, cache_dir)
}

View File

@ -98,6 +98,8 @@ impl std::fmt::Display for CfgPath {
/// Return a ProjectDirs object for the Arti project.
fn project_dirs() -> Result<&'static ProjectDirs, Error> {
/// lazy cell holding the ProjectDirs object.
// Note: this must stay in sync with sane_defaults() in the
// arti-client crate.
static PROJECT_DIRS: Lazy<Option<ProjectDirs>> =
Lazy::new(|| ProjectDirs::from("org", "torproject", "Arti"));