Skip to content

Commit

Permalink
Adjust executable dir computation to not depend on XDG_DATA_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
soc committed Sep 15, 2021
1 parent 0c63034 commit f884343
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,26 @@ dirs::executable_dir();
**If you want to compute the location of cache, config or data directories for your own application or project,
use `ProjectDirs` of the [directories](https://github.com/dirs-dev/directories-rs) project instead.**

| Function name | Value on Linux/Redox | Value on Windows | Value on macOS |
| ---------------- | ------------------------------------------------------------------------------------------------ | --------------------------------- | ------------------------------------------- |
| `home_dir` | `Some($HOME)` | `Some({FOLDERID_Profile})` | `Some($HOME)` |
| `cache_dir` | `Some($XDG_CACHE_HOME)` or `Some($HOME`/.cache`)` | `Some({FOLDERID_LocalAppData})` | `Some($HOME`/Library/Caches`)` |
| `config_dir` | `Some($XDG_CONFIG_HOME)` or `Some($HOME`/.config`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` |
| `data_dir` | `Some($XDG_DATA_HOME)` or `Some($HOME`/.local/share`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` |
| `data_local_dir` | `Some($XDG_DATA_HOME)` or `Some($HOME`/.local/share`)` | `Some({FOLDERID_LocalAppData})` | `Some($HOME`/Library/Application Support`)` |
| `executable_dir` | `Some($XDG_BIN_HOME`/../bin`)` or `Some($XDG_DATA_HOME`/../bin`)` or `Some($HOME`/.local/bin`)` | `None` | `None` |
| `preference_dir` | `Some($XDG_CONFIG_HOME)` or `Some($HOME`/.config`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Preferences`)` |
| `runtime_dir` | `Some($XDG_RUNTIME_DIR)` or `None` | `None` | `None` |
| `state_dir` | `Some($XDG_STATE_HOME)` or `Some($HOME`/.local/state`)` | `None` | `None` |
| `audio_dir` | `Some(XDG_MUSIC_DIR)` or `None` | `Some({FOLDERID_Music})` | `Some($HOME`/Music/`)` |
| `desktop_dir` | `Some(XDG_DESKTOP_DIR)` or `None` | `Some({FOLDERID_Desktop})` | `Some($HOME`/Desktop/`)` |
| `document_dir` | `Some(XDG_DOCUMENTS_DIR)` or `None` | `Some({FOLDERID_Documents})` | `Some($HOME`/Documents/`)` |
| `download_dir` | `Some(XDG_DOWNLOAD_DIR)` or `None` | `Some({FOLDERID_Downloads})` | `Some($HOME`/Downloads/`)` |
| `font_dir` | `Some($XDG_DATA_HOME`/fonts/`)` or `Some($HOME`/.local/share/fonts/`)` | `None` | `Some($HOME`/Library/Fonts/`)` |
| `picture_dir` | `Some(XDG_PICTURES_DIR)` or `None` | `Some({FOLDERID_Pictures})` | `Some($HOME`/Pictures/`)` |
| `public_dir` | `Some(XDG_PUBLICSHARE_DIR)` or `None` | `Some({FOLDERID_Public})` | `Some($HOME`/Public/`)` |
| `template_dir` | `Some(XDG_TEMPLATES_DIR)` or `None` | `Some({FOLDERID_Templates})` | `None` |
| `video_dir` | `Some(XDG_VIDEOS_DIR)` or `None` | `Some({FOLDERID_Videos})` | `Some($HOME`/Movies/`)` |
| Function name | Value on Linux/Redox | Value on Windows | Value on macOS |
| ---------------- | ---------------------------------------------------------------------- | --------------------------------- | ------------------------------------------- |
| `home_dir` | `Some($HOME)` | `Some({FOLDERID_Profile})` | `Some($HOME)` |
| `cache_dir` | `Some($XDG_CACHE_HOME)` or `Some($HOME`/.cache`)` | `Some({FOLDERID_LocalAppData})` | `Some($HOME`/Library/Caches`)` |
| `config_dir` | `Some($XDG_CONFIG_HOME)` or `Some($HOME`/.config`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` |
| `data_dir` | `Some($XDG_DATA_HOME)` or `Some($HOME`/.local/share`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` |
| `data_local_dir` | `Some($XDG_DATA_HOME)` or `Some($HOME`/.local/share`)` | `Some({FOLDERID_LocalAppData})` | `Some($HOME`/Library/Application Support`)` |
| `executable_dir` | `Some($XDG_BIN_HOME)` or `Some($HOME`/.local/bin`)` | `None` | `None` |
| `preference_dir` | `Some($XDG_CONFIG_HOME)` or `Some($HOME`/.config`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Preferences`)` |
| `runtime_dir` | `Some($XDG_RUNTIME_DIR)` or `None` | `None` | `None` |
| `state_dir` | `Some($XDG_STATE_HOME)` or `Some($HOME`/.local/state`)` | `None` | `None` |
| `audio_dir` | `Some(XDG_MUSIC_DIR)` or `None` | `Some({FOLDERID_Music})` | `Some($HOME`/Music/`)` |
| `desktop_dir` | `Some(XDG_DESKTOP_DIR)` or `None` | `Some({FOLDERID_Desktop})` | `Some($HOME`/Desktop/`)` |
| `document_dir` | `Some(XDG_DOCUMENTS_DIR)` or `None` | `Some({FOLDERID_Documents})` | `Some($HOME`/Documents/`)` |
| `download_dir` | `Some(XDG_DOWNLOAD_DIR)` or `None` | `Some({FOLDERID_Downloads})` | `Some($HOME`/Downloads/`)` |
| `font_dir` | `Some($XDG_DATA_HOME`/fonts/`)` or `Some($HOME`/.local/share/fonts/`)` | `None` | `Some($HOME`/Library/Fonts/`)` |
| `picture_dir` | `Some(XDG_PICTURES_DIR)` or `None` | `Some({FOLDERID_Pictures})` | `Some($HOME`/Pictures/`)` |
| `public_dir` | `Some(XDG_PUBLICSHARE_DIR)` or `None` | `Some({FOLDERID_Public})` | `Some($HOME`/Public/`)` |
| `template_dir` | `Some(XDG_TEMPLATES_DIR)` or `None` | `Some({FOLDERID_Templates})` | `None` |
| `video_dir` | `Some(XDG_VIDEOS_DIR)` or `None` | `Some({FOLDERID_Videos})` | `Some($HOME`/Movies/`)` |

## Comparison

Expand Down Expand Up @@ -170,6 +170,10 @@ cargo build --target=x86_64-unknown-redox
## Changelog

### 4

- **BREAKING CHANGE** The behavior of `executable_dir` has been adjusted to not depend on `$XDG_DATA_HOME`.
Code, which assumed that setting the `$XDG_DATA_HOME` environment variable also impacted `executable_dir` if
the `$XDG_BIN_HOME` environment variable was not set, requires adjustment.
- Add support for `XDG_STATE_HOME`.

### 3
Expand Down
6 changes: 1 addition & 5 deletions src/lin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ pub fn data_local_dir() -> Option<PathBuf> { data_dir() }
pub fn preference_dir() -> Option<PathBuf> { config_dir() }
pub fn runtime_dir() -> Option<PathBuf> { env::var_os("XDG_RUNTIME_DIR").and_then(dirs_sys::is_absolute_path) }
pub fn state_dir() -> Option<PathBuf> { env::var_os("XDG_STATE_HOME") .and_then(dirs_sys::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".local/state"))) }
pub fn executable_dir() -> Option<PathBuf> {
env::var_os("XDG_BIN_HOME").and_then(dirs_sys::is_absolute_path).or_else(|| {
data_dir().map(|mut e| { e.pop(); e.push("bin"); e })
})
}
pub fn executable_dir() -> Option<PathBuf> { env::var_os("XDG_BIN_HOME") .and_then(dirs_sys::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".local/bin"))) }

pub fn audio_dir() -> Option<PathBuf> { dirs_sys::user_dir("MUSIC") }
pub fn desktop_dir() -> Option<PathBuf> { dirs_sys::user_dir("DESKTOP") }
Expand Down

0 comments on commit f884343

Please sign in to comment.