Skip to content

Commit

Permalink
Avoid erroring on indeterminate home directory
Browse files Browse the repository at this point in the history
  • Loading branch information
lunacookies committed Oct 23, 2023
1 parent 76db837 commit a022291
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions crates/pipes-rs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ impl Config {
}

fn read_from_disk_with_default() -> anyhow::Result<Self> {
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<PathBuf> {
fn path() -> Option<PathBuf> {
let config_dir = 'config_dir: {
if let Ok(d) = env::var("XDG_CONFIG_HOME") {
let d = PathBuf::from(d);
Expand All @@ -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<Self> {
Expand Down

0 comments on commit a022291

Please sign in to comment.