hakurei/container/initmkdir.go
Ophestra 84549779e3
Some checks failed
Test / Create distribution (push) Successful in 34s
Test / Flake checks (push) Has been cancelled
Test / Sandbox (race detector) (push) Has been cancelled
Test / Sandbox (push) Has been cancelled
Test / Hakurei (race detector) (push) Has been cancelled
Test / Hakurei (push) Has been cancelled
Test / Hpkg (push) Has been cancelled
container/init: split setup ops into individual files
This significantly increases readability.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2025-08-20 01:26:41 +09:00

35 lines
907 B
Go

package container
import (
"encoding/gob"
"fmt"
"os"
"syscall"
)
func init() { gob.Register(new(MkdirOp)) }
// Mkdir appends an [Op] that creates a directory in the container filesystem.
func (f *Ops) Mkdir(name *Absolute, perm os.FileMode) *Ops {
*f = append(*f, &MkdirOp{name, perm})
return f
}
// MkdirOp creates a directory at container Path with permission bits set to Perm.
type MkdirOp struct {
Path *Absolute
Perm os.FileMode
}
func (m *MkdirOp) early(*setupState) error { return nil }
func (m *MkdirOp) apply(*setupState) error {
if m.Path == nil {
return syscall.EBADE
}
return wrapErrSelf(os.MkdirAll(toSysroot(m.Path.String()), m.Perm))
}
func (m *MkdirOp) Is(op Op) bool { vm, ok := op.(*MkdirOp); return ok && m == vm }
func (*MkdirOp) prefix() string { return "creating" }
func (m *MkdirOp) String() string { return fmt.Sprintf("directory %q perm %s", m.Path, m.Perm) }