about summary refs log tree commit diff
path: root/src/xdg.rs
blob: 2c130e76f55da0636bf3b238e846f835e629d005 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)
  }
}