aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/initmkdir.go
blob: d3c4bbb78985978dabacfb22a5f63a845e06d454 (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
package container

import (
	"encoding/gob"
	"fmt"
	"os"

	"hakurei.app/container/check"
)

func init() { gob.Register(new(MkdirOp)) }

// Mkdir appends an [Op] that creates a directory in the container filesystem.
func (f *Ops) Mkdir(name *check.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 *check.Absolute
	Perm os.FileMode
}

func (m *MkdirOp) Valid() bool                                { return m != nil && m.Path != nil }
func (m *MkdirOp) early(*setupState, syscallDispatcher) error { return nil }
func (m *MkdirOp) apply(_ *setupState, k syscallDispatcher) error {
	return k.mkdirAll(toSysroot(m.Path.String()), m.Perm)
}
func (m *MkdirOp) late(*setupState, syscallDispatcher) error { return nil }

func (m *MkdirOp) Is(op Op) bool {
	vm, ok := op.(*MkdirOp)
	return ok && m.Valid() && vm.Valid() &&
		m.Path.Is(vm.Path) &&
		m.Perm == vm.Perm
}
func (*MkdirOp) prefix() (string, bool) { return "creating", true }
func (m *MkdirOp) String() string       { return fmt.Sprintf("directory %q perm %s", m.Path, m.Perm) }