From 9883edd9118da0a082934d1b1dc0512e9833bda8 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Sat, 25 May 2024 01:15:14 +0200 Subject: [PATCH] try to copy the cache this doesn't work so we're gonna throw it out --- backend/src/sandbox.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/backend/src/sandbox.rs b/backend/src/sandbox.rs index ebcfe25..7b2bfc6 100644 --- a/backend/src/sandbox.rs +++ b/backend/src/sandbox.rs @@ -78,6 +78,24 @@ fn home_dir(uid: u32) -> Vec { ] } +fn copy_cache(uid: u32) -> (TempDir, Vec) { + 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) { 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 { "/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);