Skip to content

Commit

Permalink
feat(daemon): follow XDG_RUNTIME_DIR if set (#2171)
Browse files Browse the repository at this point in the history
If XDG_RUNTIME_DIR is set, put the socket file there.

If not, default to storing it in our data dir. We cannot default to a
path such as /run/user/$UID/ because it does not exist on all systems.
Any system running systemd will set this var by default, and ensure that
the directory it points to is correctly setup.
  • Loading branch information
ellie authored Jun 20, 2024
1 parent 80d28ea commit 9b82bba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/atuin-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ impl Settings {
let data_dir = atuin_common::utils::data_dir();
let db_path = data_dir.join("history.db");
let record_store_path = data_dir.join("records.db");
let socket_path = data_dir.join("atuin.sock");
let socket_path = atuin_common::utils::runtime_dir().join("atuin.sock");

let key_path = data_dir.join("key");
let session_path = data_dir.join("session");
Expand Down
4 changes: 4 additions & 0 deletions crates/atuin-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ pub fn data_dir() -> PathBuf {
data_dir.join("atuin")
}

pub fn runtime_dir() -> PathBuf {
std::env::var("XDG_RUNTIME_DIR").map_or_else(|_| data_dir(), PathBuf::from)
}

pub fn dotfiles_cache_dir() -> PathBuf {
// In most cases, this will be ~/.local/share/atuin/dotfiles/cache
let data_dir = std::env::var("XDG_DATA_HOME")
Expand Down

0 comments on commit 9b82bba

Please sign in to comment.