forked from security/hakurei
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>
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user