diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-05-29 02:12:24 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-05-29 02:12:24 -0400 |
commit | 976e602f6aa390eb7a8bb86a15a129eb96203dcf (patch) | |
tree | 6599ef3bb5394919eb1914dc3a416fa103dd6431 | |
parent | 41a1f07330d3b6680f1ee84b38b83053f7053408 (diff) | |
download | rbw-976e602f6aa390eb7a8bb86a15a129eb96203dcf.tar.gz rbw-976e602f6aa390eb7a8bb86a15a129eb96203dcf.zip |
don't require setting XDG_RUNTIME_DIR
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | src/dirs.rs | 18 |
2 files changed, 22 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 192c0d0..6e94594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +### Fixed + +* `rbw` now no longer requires the `XDG_RUNTIME_DIR` environment variable to be + set. + ## [0.4.1] - 2020-05-28 ### Fixed diff --git a/src/dirs.rs b/src/dirs.rs index fa063b8..16ce29a 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use std::os::unix::fs::PermissionsExt as _; pub fn make_all() -> Result<()> { let cache_dir = cache_dir(); @@ -6,8 +7,16 @@ pub fn make_all() -> Result<()> { .context(crate::error::CreateDirectory { file: cache_dir })?; let runtime_dir = runtime_dir(); - std::fs::create_dir_all(&runtime_dir) - .context(crate::error::CreateDirectory { file: runtime_dir })?; + std::fs::create_dir_all(&runtime_dir).context( + crate::error::CreateDirectory { + file: runtime_dir.clone(), + }, + )?; + std::fs::set_permissions( + &runtime_dir, + std::fs::Permissions::from_mode(0o700), + ) + .context(crate::error::CreateDirectory { file: runtime_dir })?; let data_dir = data_dir(); std::fs::create_dir_all(&data_dir) @@ -62,5 +71,8 @@ fn data_dir() -> std::path::PathBuf { fn runtime_dir() -> std::path::PathBuf { let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap(); - project_dirs.runtime_dir().unwrap().to_path_buf() + match project_dirs.runtime_dir() { + Some(dir) => dir.to_path_buf(), + None => format!("/tmp/rbw-{}", nix::unistd::getuid().as_raw()).into(), + } } |