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:
commit
580f878273
@ -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") {
|
||||||
|
Loading…
Reference in New Issue
Block a user