1
Fork 0

try to copy the cache

this doesn't work so we're gonna throw it out
This commit is contained in:
Jan-Erik Rediger 2024-05-25 01:15:14 +02:00
parent 41693bebbb
commit 9883edd911

View file

@ -78,6 +78,24 @@ fn home_dir(uid: u32) -> Vec<String> {
]
}
fn copy_cache(uid: u32) -> (TempDir, Vec<String>) {
let cache_dir = format!("/run/user/{uid}/home/.cache/hare");
let tmp_cache_dir = tempfile::tempdir().unwrap();
let src_dir = "/root/.cache/hare/usr";
let opts = fs_extra::dir::CopyOptions::new();
fs_extra::copy_items(&[src_dir], tmp_cache_dir.path(), &opts).unwrap();
let tmp_cache_dir_path = tmp_cache_dir.path().display().to_string();
(tmp_cache_dir,
vec![
"--bind".to_string(),
tmp_cache_dir_path,
cache_dir,
])
}
fn shared_app_dir() -> (TempDir, Vec<String>) {
let tmp_app_dir = tempfile::tempdir().unwrap();
let app_dir_path = tmp_app_dir.path().display().to_string();
@ -99,6 +117,7 @@ fn command(app_file: &str) -> Vec<String> {
"/usr/bin/timeout".to_string(), DEFAULT_TIMEOUT.to_string(),
HARE_COMMAND.to_string(),
"run".to_string(),
"-v".to_string(),
app_file.to_string(),
]
}
@ -119,6 +138,9 @@ pub fn run_code(code: &str) -> std::process::Output {
let home_args = home_dir(uid);
bwrap_cmd.args(home_args);
let (_cache_dir, cache_args) = copy_cache(uid);
bwrap_cmd.args(cache_args);
let (_passwd, _group, file_args) = passwd_files(uid, gid);
bwrap_cmd.args(file_args);