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

View file

@ -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()),

View file

@ -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));