Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 13 additions & 11 deletions crates/lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ fn get_pantry_dir() -> io::Result<PathBuf> {
}

fn get_pkgx_dir() -> io::Result<PathBuf> {
if let Ok(env_dir) = env::var("PKGX_DIR") {
let path = PathBuf::from(env_dir);
if !path.is_absolute() {
return Ok(env::current_dir()?.join(path));
} else {
if let Ok(path) = env::var("PKGX_DIR") {
let path = PathBuf::from(path);
if path.is_absolute() {
return Ok(path);
}
}
#[cfg(target_os = "macos")]
return Ok(dirs_next::home_dir().unwrap().join(".pkgx"));
#[cfg(target_os = "linux")]
return Ok(dirs_next::home_dir().unwrap().join(".pkgx"));
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
panic!("Unsupported platform")

let default = dirs_next::home_dir().map(|x| x.join(".pkgx"));

if default.clone().is_some_and(|x| x.exists()) {
Ok(default.unwrap())
} else if let Ok(xdg) = env::var("XDG_DATA_HOME") {
Ok(PathBuf::from(xdg).join("pkgx"))
} else {
Ok(default.unwrap())
}
}
19 changes: 14 additions & 5 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,20 @@ following [semver] syntax:

## Where does `pkgx` store files

* pkgs are downloaded to `~/.pkgx` (`$PKGX_DIR` overrides)
* runtime data like the [pantry] is stored in:
* `~/Library/Caches/pkgx` on Mac
* `${XDG_CACHE_HOME:-$HOME/.cache}/pkgx` on *nix
* `%LOCALAPPDATA%/pkgx` on Windows
Packages are downloaded to `$PKGX_DIR` if set. If not set:

* macOS
* `~/Library/Packages` if the directory exists
* `~/.pkgx` otherwise
* *nix
* `~/.pkgx` if the directory exists
* `${XDG_DATA_HOME:-$HOME/.local/share}/pkgx` otherwise

Some cache data is stored:

* `~/Library/Caches/pkgx` on Mac
* `${XDG_CACHE_HOME:-$HOME/.cache}/pkgx` on *nix
* `%LOCALAPPDATA%/pkgx` on Windows


## What happens if two packages provide the same named program?
Expand Down