summarylogtreecommitdiffstats
path: root/fix-sandbox.patch
blob: 6e149dc4cf93457c3db240b7b0307e0d8f1c42e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
diff --git a/src/config/schema_blanks/sandbox/mod.rs b/src/config/schema_blanks/sandbox/mod.rs
index a6b3590..36305d9 100644
--- a/src/config/schema_blanks/sandbox/mod.rs
+++ b/src/config/schema_blanks/sandbox/mod.rs
@@ -1,5 +1,6 @@
 use serde::{Serialize, Deserialize};
 use serde_json::Value as JsonValue;
+use std::fs::metadata;
 
 mod mounts;
 
@@ -141,15 +142,53 @@ impl Sandbox {
         }
 
         if self.isolate_home {
-            command.push_str(" --tmpfs /home");
-            command.push_str(" --tmpfs /var/home");
+            match metadata("/home") {
+                Ok(meta) => {
+                    if meta.is_dir() {
+                        command.push_str(" --tmpfs /home");
+                    } else {
+                        tracing::info!("/var/home is not a directory.")
+                    }
+                },
+                Err(_) => tracing::info!("/home does not exist.")
+            }
+            match metadata("/var/home") {
+                Ok(meta) => {
+                    if meta.is_dir() {
+                        command.push_str(" --tmpfs /var/home");
+                    } else {
+                        tracing::info!("/var/home is not a directory.")
+                    }
+                },
+                Err(_) => tracing::info!("/var/home does not exist.")
+            }
 
             if let Ok(user) = std::env::var("USER") {
-                command += &format!(" --tmpfs '/var/home/{}'", user.trim());
+                let dir = format!("/var/home/{}", user.trim());
+                match metadata(&dir) {
+                    Ok(meta) => {
+                        if meta.is_dir() {
+                            command += &format!(" --tmpfs '{}'", dir);
+                        } else {
+                            tracing::info!("{} is not a directory.", dir)
+                        }
+                    },
+                    Err(_) => tracing::info!("{} does not exist.", dir)
+                }
             }
 
             if let Ok(home) = std::env::var("HOME") {
-                command += &format!(" --tmpfs '{}'", home.trim());
+                let dir = home.trim();
+                match metadata(dir) {
+                    Ok(meta) => {
+                        if meta.is_dir() {
+                            command += &format!(" --tmpfs '{}'", dir);
+                        } else {
+                            tracing::info!("{} is not a directory.", dir)
+                        }
+                    },
+                    Err(_) => tracing::info!("{} does not exist.", dir)
+                }
             }
         }