aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/mkdir.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-02 04:54:34 +0900
committerOphestra <cat@gensokyo.uk>2025-09-02 04:54:34 +0900
commit6f719bc3c19d56279d2d76d3bcf8fb66ace2d2fb (patch)
tree6e9e84fd6f382fa823c87a70a0df0284dc127250 /system/mkdir.go
parent1b5d20a39b2c5720d83a8eaf3d2227deb46a7c0d (diff)
system: update doc commands and remove mutex
The mutex is not really doing anything, none of these methods make sense when called concurrently anyway. The copylocks analysis is still satisfied by the noCopy struct. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/mkdir.go')
-rw-r--r--system/mkdir.go40
1 files changed, 15 insertions, 25 deletions
diff --git a/system/mkdir.go b/system/mkdir.go
index 51fc2744..4fba4afd 100644
--- a/system/mkdir.go
+++ b/system/mkdir.go
@@ -6,38 +6,30 @@ import (
"os"
)
-// Ensure the existence and mode of a directory.
+// Ensure appends [MkdirOp] to [I] with its [Enablement] ignored.
func (sys *I) Ensure(name string, perm os.FileMode) *I {
- sys.lock.Lock()
- defer sys.lock.Unlock()
-
- sys.ops = append(sys.ops, &Mkdir{User, name, perm, false})
-
+ sys.ops = append(sys.ops, &MkdirOp{User, name, perm, false})
return sys
}
-// Ephemeral ensures the temporary existence and mode of a directory through the life of et.
+// Ephemeral appends an ephemeral [MkdirOp] to [I].
func (sys *I) Ephemeral(et Enablement, name string, perm os.FileMode) *I {
- sys.lock.Lock()
- defer sys.lock.Unlock()
-
- sys.ops = append(sys.ops, &Mkdir{et, name, perm, true})
-
+ sys.ops = append(sys.ops, &MkdirOp{et, name, perm, true})
return sys
}
-type Mkdir struct {
+// MkdirOp ensures the existence of a directory.
+// For ephemeral, the directory is destroyed once [Enablement] is no longer satisfied.
+type MkdirOp struct {
et Enablement
path string
perm os.FileMode
ephemeral bool
}
-func (m *Mkdir) Type() Enablement {
- return m.et
-}
+func (m *MkdirOp) Type() Enablement { return m.et }
-func (m *Mkdir) apply(*I) error {
+func (m *MkdirOp) apply(*I) error {
msg.Verbose("ensuring directory", m)
// create directory
@@ -52,7 +44,7 @@ func (m *Mkdir) apply(*I) error {
}
}
-func (m *Mkdir) revert(_ *I, ec *Criteria) error {
+func (m *MkdirOp) revert(_ *I, ec *Criteria) error {
if !m.ephemeral {
// skip non-ephemeral dir and do not log anything
return nil
@@ -67,16 +59,14 @@ func (m *Mkdir) revert(_ *I, ec *Criteria) error {
}
}
-func (m *Mkdir) Is(o Op) bool {
- m0, ok := o.(*Mkdir)
- return ok && m0 != nil && *m == *m0
+func (m *MkdirOp) Is(o Op) bool {
+ target, ok := o.(*MkdirOp)
+ return ok && m != nil && target != nil && *m == *target
}
-func (m *Mkdir) Path() string {
- return m.path
-}
+func (m *MkdirOp) Path() string { return m.path }
-func (m *Mkdir) String() string {
+func (m *MkdirOp) String() string {
t := "ensure"
if m.ephemeral {
t = TypeString(m.Type())