From a02229183cc7112820a3429929b4bff3419d04cb Mon Sep 17 00:00:00 2001 From: Luna Razzaghipour Date: Mon, 23 Oct 2023 19:16:37 +1100 Subject: [PATCH] Avoid erroring on indeterminate home directory --- crates/pipes-rs/src/config.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/pipes-rs/src/config.rs b/crates/pipes-rs/src/config.rs index 3dbcaae..f4ed711 100644 --- a/crates/pipes-rs/src/config.rs +++ b/crates/pipes-rs/src/config.rs @@ -29,16 +29,16 @@ impl Config { } fn read_from_disk_with_default() -> anyhow::Result { - let path = Self::path()?; - - if !path.exists() { - return Ok(Config::default()); + if let Some(path) = Self::path() { + if path.exists() { + return Self::read_from_disk(path); + } } - Self::read_from_disk(path) + Ok(Config::default()) } - fn path() -> anyhow::Result { + fn path() -> Option { let config_dir = 'config_dir: { if let Ok(d) = env::var("XDG_CONFIG_HOME") { let d = PathBuf::from(d); @@ -47,13 +47,10 @@ impl Config { } } - match home::home_dir() { - Some(d) => d.join(".config/"), - None => anyhow::bail!("could not determine home directory"), - } + home::home_dir()?.join(".config/") }; - Ok(config_dir.join("pipes-rs/config.toml")) + Some(config_dir.join("pipes-rs/config.toml")) } fn read_from_disk(path: PathBuf) -> anyhow::Result {