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:
parent
663ce42016
commit
38fbfbd918
4 changed files with 57 additions and 29 deletions
60
Cargo.lock
generated
60
Cargo.lock
generated
|
|
@ -290,6 +290,27 @@ version = "0.1.13"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "dlib"
|
||||
version = "0.5.2"
|
||||
|
|
@ -371,8 +392,8 @@ dependencies = [
|
|||
"bytes",
|
||||
"copypasta",
|
||||
"crossterm",
|
||||
"directories-next",
|
||||
"env_logger",
|
||||
"home",
|
||||
"indoc",
|
||||
"libc",
|
||||
"log",
|
||||
|
|
@ -386,7 +407,6 @@ dependencies = [
|
|||
"tokio",
|
||||
"tokio-stream",
|
||||
"toml",
|
||||
"xdg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -450,15 +470,6 @@ version = "0.4.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.60"
|
||||
|
|
@ -561,6 +572,16 @@ dependencies = [
|
|||
"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]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.1.4"
|
||||
|
|
@ -890,6 +911,17 @@ dependencies = [
|
|||
"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]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.24"
|
||||
|
|
@ -1679,12 +1711,6 @@ version = "0.3.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61"
|
||||
|
||||
[[package]]
|
||||
name = "xdg"
|
||||
version = "2.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
|
||||
|
||||
[[package]]
|
||||
name = "xkeysym"
|
||||
version = "0.2.1"
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ anyhow = "1.0"
|
|||
bytes = "1"
|
||||
copypasta = "0.10.1"
|
||||
crossterm = { version = "0.28.1", features = ["event-stream"] }
|
||||
directories-next = "2"
|
||||
env_logger = { version = "0.11.5", default-features = false }
|
||||
home = "0.5.4"
|
||||
indoc = "1"
|
||||
log = { version = "0.4", features = ["std"] }
|
||||
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-stream = "0.1"
|
||||
toml = "0.5"
|
||||
xdg = "2"
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1"
|
||||
|
|
|
|||
|
|
@ -62,13 +62,15 @@ impl Config {
|
|||
pub fn load_config() -> Result<Config> {
|
||||
use std::io::ErrorKind;
|
||||
|
||||
let mut home = match home::home_dir() {
|
||||
Some(h) => h,
|
||||
None => return Ok(default()),
|
||||
let Some(directories) = directories_next::ProjectDirs::from("", "", "fwd")
|
||||
else {
|
||||
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,
|
||||
Err(e) => match e.kind() {
|
||||
ErrorKind::NotFound => return Ok(default()),
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@ pub fn socket_path() -> Result<PathBuf> {
|
|||
}
|
||||
|
||||
fn socket_directory() -> Result<std::path::PathBuf> {
|
||||
let base_directories = xdg::BaseDirectories::new()
|
||||
.context("Error creating BaseDirectories")?;
|
||||
match base_directories.place_runtime_file("fwd") {
|
||||
Ok(path) => Ok(path),
|
||||
Err(_) => {
|
||||
match directories_next::ProjectDirs::from("", "", "fwd")
|
||||
.and_then(|p| p.runtime_dir().map(|p| p.to_path_buf()))
|
||||
{
|
||||
Some(p) => Ok(p),
|
||||
None => {
|
||||
let mut path = std::env::temp_dir();
|
||||
let uid = unsafe { libc::getuid() };
|
||||
path.push(format!("fwd{}", uid));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue