Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support XDG_CONFIG_HOME for receipts #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions axoupdater/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,27 @@ pub(crate) fn get_config_path(app_name: &str) -> AxoupdateResult<Utf8PathBuf> {
} else if let Ok(path) = env::var("AXOUPDATER_CONFIG_PATH") {
Ok(Utf8PathBuf::from(path))
} else {
let xdg_home = env::var("XDG_CONFIG_HOME")
.ok()
.map(PathBuf::from)
.map(|h| h.join(app_name));
let xdg_home_exists = xdg_home.as_ref().map(|h| h.exists()).unwrap_or(false);

let home = if cfg!(windows) {
env::var("LOCALAPPDATA").map(PathBuf::from).ok()
env::var("LOCALAPPDATA")
.map(PathBuf::from)
.map(|h| h.join(app_name))
.ok()
} else if xdg_home_exists {
xdg_home
} else {
homedir::my_home()?.map(|path| path.join(".config"))
homedir::my_home()?.map(|path| path.join(".config").join(app_name))
};
let Some(home) = home else {
return Err(AxoupdateError::NoHome {});
};

Ok(Utf8PathBuf::try_from(home)?.join(app_name))
Ok(Utf8PathBuf::try_from(home)?)
}
}

Expand Down
Loading