Skip to content

Commit

Permalink
Merge pull request #488 from dgibson/runtime-subdir
Browse files Browse the repository at this point in the history
Create a subdirectory under XDG_RUNTIME_DIR
  • Loading branch information
Furisto authored Nov 23, 2021
2 parents e766310 + 6a49688 commit 580f878
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/youki/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod commands;
mod logger;

use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use anyhow::bail;
use anyhow::Context;
Expand Down Expand Up @@ -145,15 +145,18 @@ fn determine_root_path(root_path: Option<PathBuf>) -> Result<PathBuf> {
}

// see https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
let uid = getuid().as_raw();
if let Ok(path) = std::env::var("XDG_RUNTIME_DIR") {
return Ok(PathBuf::from(path));
let path = Path::new(&path).join("youki");
if create_dir_all_with_mode(&path, uid, Mode::S_IRWXU).is_ok() {
return Ok(path);
}
}

// XDG_RUNTIME_DIR is not set, try the usual location
let uid = getuid().as_raw();
let runtime_dir = PathBuf::from(format!("/run/user/{}", uid));
if create_dir_all_with_mode(&runtime_dir, uid, Mode::S_IRWXU).is_ok() {
return Ok(runtime_dir);
let path = PathBuf::from(format!("/run/user/{}/youki", uid));
if create_dir_all_with_mode(&path, uid, Mode::S_IRWXU).is_ok() {
return Ok(path);
}

if let Ok(path) = std::env::var("HOME") {
Expand Down

0 comments on commit 580f878

Please sign in to comment.