Skip to content

Commit

Permalink
fix: use correct xdg paths on windows (#2653)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Sep 25, 2024
1 parent 22251ce commit 6cb1c60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use std::{env, fs};

fn main() {
cfg_aliases::cfg_aliases! {
vfox: { any(feature = "vfox", target_os = "windows") },
asdf: { any(feature = "asdf", not(target_os = "windows")) },
macos: { target_os = "macos" },
vfox: { any(feature = "vfox", target_os = "windows") },
}
built::write_built_file().expect("Failed to acquire build-time information");

Expand Down
17 changes: 15 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,29 @@ pub static HOME: Lazy<PathBuf> =
pub static EDITOR: Lazy<String> =
Lazy::new(|| var("VISUAL").unwrap_or_else(|_| var("EDITOR").unwrap_or_else(|_| "nano".into())));

#[cfg(target_os = "macos")]
#[cfg(macos)]
pub static XDG_CACHE_HOME: Lazy<PathBuf> =
Lazy::new(|| var_path("XDG_CACHE_HOME").unwrap_or_else(|| HOME.join("Library/Caches")));
#[cfg(not(target_os = "macos"))]
#[cfg(windows)]
pub static XDG_CACHE_HOME: Lazy<PathBuf> = Lazy::new(|| {
var_path("XDG_CACHE_HOME")
.or_else(|| var_path("TEMP"))
.unwrap_or_else(|| temp_dir())
});
#[cfg(all(not(windows), not(macos)))]
pub static XDG_CACHE_HOME: Lazy<PathBuf> =
Lazy::new(|| var_path("XDG_CACHE_HOME").unwrap_or_else(|| HOME.join(".cache")));
pub static XDG_CONFIG_HOME: Lazy<PathBuf> =
Lazy::new(|| var_path("XDG_CONFIG_HOME").unwrap_or_else(|| HOME.join(".config")));
#[cfg(unix)]
pub static XDG_DATA_HOME: Lazy<PathBuf> =
Lazy::new(|| var_path("XDG_DATA_HOME").unwrap_or_else(|| HOME.join(".local").join("share")));
#[cfg(windows)]
pub static XDG_DATA_HOME: Lazy<PathBuf> = Lazy::new(|| {
var_path("XDG_DATA_HOME")
.or(var_path("LOCALAPPDATA"))
.unwrap_or_else(|| HOME.join("AppData/Local"))
});
pub static XDG_STATE_HOME: Lazy<PathBuf> =
Lazy::new(|| var_path("XDG_STATE_HOME").unwrap_or_else(|| HOME.join(".local").join("state")));

Expand Down

0 comments on commit 6cb1c60

Please sign in to comment.