diff --git a/Cargo.lock b/Cargo.lock index e124de95b..288156311 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/crates/arti-client/Cargo.toml b/crates/arti-client/Cargo.toml index e619f76d6..76dae2239 100644 --- a/crates/arti-client/Cargo.toml +++ b/crates/arti-client/Cargo.toml @@ -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"] } diff --git a/crates/arti-client/src/config.rs b/crates/arti-client/src/config.rs index 3d4d7c03b..606fd02dc 100644 --- a/crates/arti-client/src/config.rs +++ b/crates/arti-client/src/config.rs @@ -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 { - 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) } diff --git a/crates/tor-config/src/path.rs b/crates/tor-config/src/path.rs index 6a8630330..375468716 100644 --- a/crates/tor-config/src/path.rs +++ b/crates/tor-config/src/path.rs @@ -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> = Lazy::new(|| ProjectDirs::from("org", "torproject", "Arti"));