diff options
Diffstat (limited to 'src/xdg.rs')
| -rw-r--r-- | src/xdg.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/xdg.rs b/src/xdg.rs new file mode 100644 index 0000000..2c130e7 --- /dev/null +++ b/src/xdg.rs @@ -0,0 +1,27 @@ +use crate::Result; + +use std::path::PathBuf; + + +/* The spec does not suggest a default for this one, merely saying that + * applications should fall back to something else. So, we return an Option to + * allow our caller to worry about that. + */ +pub fn xdg_runtime_directory() -> Result<Option<PathBuf>> { + if let Ok(mut path) = std::env::var("XDG_RUNTIME_DIR") { + /* As nice as it would be to use a portable interface for this, Rust + * doesn't have a stable one yet. In fact, we barely have visibility into + * it at all once we convert to a path. + * + * Oh well. Fuck Microsoft anyway. + */ + if !path.ends_with("/") { + path.push_str("/"); + } + + Ok(Some(PathBuf::from(path))) + } else { + Ok(None) + } +} + |