~goorzhel/radm

8f41fd3386d103402d3fe7841c3e76a1d7c17949 — Antonio Gurgel 3 months ago 4378fef
Rename to env_var_or_set_default

The "set_" might help lessen the astonishment (hence, POLA).
2 files changed, 3 insertions(+), 3 deletions(-)

M src/system.rs
M src/user.rs
M src/system.rs => src/system.rs +1 -1
@@ 49,7 49,7 @@ pub fn prepare_xdg_runtime(user: &User) -> Result<()> {
}

/// Reads an environment variable; if unset, sets it to the given default.
pub fn env_var_or_default<K: AsRef<OsStr> + Display, D: AsRef<OsStr> + Display>(
pub fn env_var_or_set_default<K: AsRef<OsStr> + Display, D: AsRef<OsStr> + Display>(
    key: K,
    default: D,
) -> String {

M src/user.rs => src/user.rs +2 -2
@@ 17,7 17,7 @@ use xdg::BaseDirectories;
use crate::{
    cli::Dbus,
    session::Desktop,
    system::env_var_or_default,
    system::env_var_or_set_default,
    tui::{prompt, EchoInput},
};



@@ 76,7 76,7 @@ impl User {

        // `xdg` crate doesn't assume $XDG_RUNTIME_DIR. `rstdm` will default to `/run/user/$UID`
        // until there's reason to do otherwise.
        env_var_or_default("XDG_RUNTIME_DIR", format!("/run/user/{}", self.uid));
        env_var_or_set_default("XDG_RUNTIME_DIR", format!("/run/user/{}", self.uid));

        Ok(BaseDirectories::new()?)
    }