aboutsummaryrefslogtreecommitdiffhomepage
path: root/sandbox/sequential.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-17 22:03:06 +0900
committerOphestra <cat@gensokyo.uk>2025-03-17 22:03:06 +0900
commit228f3301f2e152855c2b63160945d6d01bb8cb30 (patch)
tree86239ece0df88e6a5a273c25c06cc27bc86ca6bb /sandbox/sequential.go
parent07181138e5abdf78dfcd6e9100362349ec4a81e8 (diff)
sandbox: create directories
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'sandbox/sequential.go')
-rw-r--r--sandbox/sequential.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/sandbox/sequential.go b/sandbox/sequential.go
index 1ffe4e7e..f9c2e29d 100644
--- a/sandbox/sequential.go
+++ b/sandbox/sequential.go
@@ -234,3 +234,31 @@ func (f *Ops) Link(target, linkName string) *Ops {
*f = append(*f, &Symlink{target, linkName})
return f
}
+
+func init() { gob.Register(new(Mkdir)) }
+
+// Mkdir creates a directory in the container filesystem.
+type Mkdir string
+
+func (m Mkdir) apply(*Params) error {
+ v := string(m)
+
+ if !path.IsAbs(v) {
+ return msg.WrapErr(syscall.EBADE,
+ fmt.Sprintf("path %q is not absolute", v))
+ }
+
+ target := toSysroot(v)
+ if err := os.MkdirAll(target, 0755); err != nil {
+ return msg.WrapErr(err, err.Error())
+ }
+ return nil
+}
+
+func (m Mkdir) Is(op Op) bool { vm, ok := op.(Mkdir); return ok && m == vm }
+func (Mkdir) prefix() string { return "creating" }
+func (m Mkdir) String() string { return fmt.Sprintf("directory %q", string(m)) }
+func (f *Ops) Mkdir(dest string) *Ops {
+ *f = append(*f, Mkdir(dest))
+ return f
+}