diff --git a/Cargo.lock b/Cargo.lock index 225d787..d79db91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,16 +109,6 @@ dependencies = [ "dirs-sys", ] -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - [[package]] name = "dirs-sys" version = "0.4.1" @@ -131,17 +121,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "displaydoc" version = "0.2.5" @@ -175,6 +154,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "etcetera" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de48cc4d1c1d97a20fd819def54b890cadde72ed3ad0c614822a0a433361be96" +dependencies = [ + "cfg-if", + "windows-sys 0.61.2", +] + [[package]] name = "fastrand" version = "2.0.2" @@ -670,7 +659,7 @@ name = "rustypaste-cli" version = "0.9.4" dependencies = [ "colored", - "dirs-next", + "etcetera", "getopts", "indicatif", "multipart", @@ -1089,26 +1078,10 @@ dependencies = [ ] [[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-sys" @@ -1137,6 +1110,15 @@ dependencies = [ "windows-targets 0.53.2", ] +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index 2fc6b2f..fd2b573 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ use-native-certs = ["ureq/native-certs"] [dependencies] serde = { version = "1.0.228", default-features = false, features = ["derive"] } toml = "1.1.0" -dirs-next = "2.0.0" thiserror = "2.0.18" getopts = "0.2.24" ureq = { version = "2.12.1", features = ["json"] } @@ -34,6 +33,7 @@ colored = "3.1.1" url = "2.5.8" indicatif = "0.18.4" shellexpand = "3.1.2" +etcetera = "0.11.0" [profile.release] opt-level = 3 diff --git a/src/config.rs b/src/config.rs index 5f7571e..8af52c0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,6 @@ use crate::args::Args; use serde::{Deserialize, Serialize}; use std::fs; -#[cfg(target_os = "macos")] -use std::{env, path::PathBuf}; /// Configuration values. #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -96,22 +94,6 @@ impl Config { }; }; } - - /// Find a special config path on macOS. - /// - /// The `dirs-next` crate ignores the `XDG_CONFIG_HOME` env var on macOS and only considers - /// `Library/Application Support` as the config dir, which is primarily used by GUI apps. - /// - /// This function determines the config path and honors the `XDG_CONFIG_HOME` env var. - /// If it is not set, it will fall back to `~/.config` - #[cfg(target_os = "macos")] - pub(crate) fn retrieve_xdg_config_on_macos(&self) -> PathBuf { - let config_dir = env::var("XDG_CONFIG_HOME").map_or_else( - |_| dirs_next::home_dir().unwrap_or_default().join(".config"), - PathBuf::from, - ); - config_dir.join("rustypaste") - } } #[cfg(test)] diff --git a/src/lib.rs b/src/lib.rs index 7fcce80..d3893b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ use crate::config::Config; use crate::error::{Error, Result}; use crate::upload::Uploader; use colored::Colorize; +use etcetera::BaseStrategy; use std::fs; use std::io::IsTerminal; use std::io::{self, Read}; @@ -30,14 +31,26 @@ pub fn run(args: Args) -> Result<()> { if let Some(ref config_path) = args.config { config = toml::from_str(&fs::read_to_string(config_path)?)? } else { + // cannot panic - see https://github.com/lunacookies/etcetera/issues/42 + let strategy = etcetera::choose_base_strategy() + .expect("cannot determine current OS's default strategy (layout)"); for path in [ - dirs_next::home_dir().map(|p| p.join(".rustypaste").join(CONFIG_FILE)), + strategy.config_dir().join("rustypaste").join(CONFIG_FILE), + // paths for backwards compatibility + #[cfg(target_family = "unix")] + strategy + .home_dir() + .to_path_buf() + .join(".rustypaste") + .join(CONFIG_FILE), #[cfg(target_os = "macos")] - Some(config.retrieve_xdg_config_on_macos().join(CONFIG_FILE)), - dirs_next::config_dir().map(|p| p.join("rustypaste").join(CONFIG_FILE)), + strategy + .home_dir() + .to_path_buf() + .join("Library/Application Support/rustypaste") + .join(CONFIG_FILE), ] .iter() - .filter_map(|v| v.as_ref()) { if path.exists() { config = toml::from_str(&fs::read_to_string(path)?)?;