Skip to content

Commit

Permalink
fix(aura): auto-generate conf dir if it doesn't exist
Browse files Browse the repository at this point in the history
This enables the `aura conf --gen > ...` line advertised everywhere to
work the first time.

See #864
  • Loading branch information
fosskers committed Jul 31, 2024
1 parent 941a5cc commit eb0d994
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- `-s --reverse` can be turned on permanently in config.
- `--asdeps` reinstated.

#### Fixed

- Auto-generate the `~/.config/aura/` directory if it doesn't exist.

## 4.0.0 (2024-07-31)

Aura 4 represents a signicant body of work to port Aura from Haskell to Rust.
Expand Down
14 changes: 9 additions & 5 deletions rust/aura-pm/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ pub(crate) fn xdg_config() -> Result<PathBuf, Error> {
}

/// The location of Aura's config file.
///
/// `~/.config/aura/` is automatically created if it doesn't exist.
pub(crate) fn aura_config() -> Result<PathBuf, Error> {
xdg_config().map(|p| p.join("aura").join("config.toml"))
}
let xdg = xdg_config()?;
let dir = xdg.join("aura");

if dir.is_dir().not() {
std::fs::create_dir_all(&dir).map_err(|e| Error::Mkdir(dir.clone(), e))?;
}

/// The previous location of Aura's config file.
pub(crate) fn aura_config_old() -> Result<PathBuf, Error> {
xdg_config().map(|p| p.join("aura.toml"))
Ok(dir.join("config.toml"))
}

/// Fetch the path value of `$XDG_CACHE_HOME` or provide its default according
Expand Down
10 changes: 1 addition & 9 deletions rust/aura-pm/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,7 @@ struct RawEnv {
impl RawEnv {
/// Attempt to read and parse settings from the filesystem.
fn try_new() -> Option<Self> {
let config: PathBuf = {
let c = dirs::aura_config().ok()?;
if c.is_file() {
c
} else {
dirs::aura_config_old().ok()?
}
};

let config: PathBuf = dirs::aura_config().ok()?;
debug!("Reading: {}", config.display());
let s = std::fs::read_to_string(config).ok()?;
basic_toml::from_str(&s).ok()
Expand Down

0 comments on commit eb0d994

Please sign in to comment.