Move config file to ~/.config/fwd/config.toml

Presumably this also works for MacOS and windows.

While doing this, move away from xdg and home and use this
directories-next crate instead. Reverse connections still seem to
work.
This commit is contained in:
John Doty 2024-08-14 10:51:19 -07:00
parent 663ce42016
commit 38fbfbd918
4 changed files with 57 additions and 29 deletions

60
Cargo.lock generated
View file

@ -290,6 +290,27 @@ version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
[[package]]
name = "directories-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc"
dependencies = [
"cfg-if",
"dirs-sys-next",
]
[[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]] [[package]]
name = "dlib" name = "dlib"
version = "0.5.2" version = "0.5.2"
@ -371,8 +392,8 @@ dependencies = [
"bytes", "bytes",
"copypasta", "copypasta",
"crossterm", "crossterm",
"directories-next",
"env_logger", "env_logger",
"home",
"indoc", "indoc",
"libc", "libc",
"log", "log",
@ -386,7 +407,6 @@ dependencies = [
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"toml", "toml",
"xdg",
] ]
[[package]] [[package]]
@ -450,15 +470,6 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "home"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
dependencies = [
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.60" version = "0.1.60"
@ -561,6 +572,16 @@ dependencies = [
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.6.0",
"libc",
]
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.1.4" version = "0.1.4"
@ -890,6 +911,17 @@ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
] ]
[[package]]
name = "redox_users"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891"
dependencies = [
"getrandom",
"libredox",
"thiserror",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.24" version = "0.1.24"
@ -1679,12 +1711,6 @@ version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61" checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61"
[[package]]
name = "xdg"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
[[package]] [[package]]
name = "xkeysym" name = "xkeysym"
version = "0.2.1" version = "0.2.1"

View file

@ -18,8 +18,8 @@ anyhow = "1.0"
bytes = "1" bytes = "1"
copypasta = "0.10.1" copypasta = "0.10.1"
crossterm = { version = "0.28.1", features = ["event-stream"] } crossterm = { version = "0.28.1", features = ["event-stream"] }
directories-next = "2"
env_logger = { version = "0.11.5", default-features = false } env_logger = { version = "0.11.5", default-features = false }
home = "0.5.4"
indoc = "1" indoc = "1"
log = { version = "0.4", features = ["std"] } log = { version = "0.4", features = ["std"] }
open = "3" open = "3"
@ -29,7 +29,7 @@ thiserror = "1.0"
tokio = { version = "1", features = ["io-std", "io-util", "macros", "net", "process", "rt", "rt-multi-thread", "fs"] } tokio = { version = "1", features = ["io-std", "io-util", "macros", "net", "process", "rt", "rt-multi-thread", "fs"] }
tokio-stream = "0.1" tokio-stream = "0.1"
toml = "0.5" toml = "0.5"
xdg = "2"
[dev-dependencies] [dev-dependencies]
assert_matches = "1" assert_matches = "1"

View file

@ -62,13 +62,15 @@ impl Config {
pub fn load_config() -> Result<Config> { pub fn load_config() -> Result<Config> {
use std::io::ErrorKind; use std::io::ErrorKind;
let mut home = match home::home_dir() { let Some(directories) = directories_next::ProjectDirs::from("", "", "fwd")
Some(h) => h, else {
None => return Ok(default()), return Ok(default());
}; };
home.push(".fwd");
let contents = match std::fs::read_to_string(home) { let mut config_path = directories.config_dir().to_path_buf();
config_path.push("config.toml");
let contents = match std::fs::read_to_string(config_path) {
Ok(contents) => contents, Ok(contents) => contents,
Err(e) => match e.kind() { Err(e) => match e.kind() {
ErrorKind::NotFound => return Ok(default()), ErrorKind::NotFound => return Ok(default()),

View file

@ -49,11 +49,11 @@ pub fn socket_path() -> Result<PathBuf> {
} }
fn socket_directory() -> Result<std::path::PathBuf> { fn socket_directory() -> Result<std::path::PathBuf> {
let base_directories = xdg::BaseDirectories::new() match directories_next::ProjectDirs::from("", "", "fwd")
.context("Error creating BaseDirectories")?; .and_then(|p| p.runtime_dir().map(|p| p.to_path_buf()))
match base_directories.place_runtime_file("fwd") { {
Ok(path) => Ok(path), Some(p) => Ok(p),
Err(_) => { None => {
let mut path = std::env::temp_dir(); let mut path = std::env::temp_dir();
let uid = unsafe { libc::getuid() }; let uid = unsafe { libc::getuid() };
path.push(format!("fwd{}", uid)); path.push(format!("fwd{}", uid));