1
0
mirror of https://github.com/containers/youki synced 2024-09-29 15:31:20 +02:00

Merge pull request #488 from dgibson/runtime-subdir

Create a subdirectory under XDG_RUNTIME_DIR
This commit is contained in:
Thomas Schubart 2021-11-23 13:20:20 +01:00 committed by GitHub
commit 580f878273
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23

@ -5,7 +5,7 @@ mod commands;
mod logger; mod logger;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::{Path, PathBuf};
use anyhow::bail; use anyhow::bail;
use anyhow::Context; use anyhow::Context;
@ -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 // 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") { 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 // XDG_RUNTIME_DIR is not set, try the usual location
let uid = getuid().as_raw(); let path = PathBuf::from(format!("/run/user/{}/youki", uid));
let runtime_dir = PathBuf::from(format!("/run/user/{}", uid)); if create_dir_all_with_mode(&path, uid, Mode::S_IRWXU).is_ok() {
if create_dir_all_with_mode(&runtime_dir, uid, Mode::S_IRWXU).is_ok() { return Ok(path);
return Ok(runtime_dir);
} }
if let Ok(path) = std::env::var("HOME") { if let Ok(path) = std::env::var("HOME") {