All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 1m51s
Test / Hakurei (push) Successful in 3m18s
Test / Hpkg (push) Successful in 3m41s
Test / Sandbox (race detector) (push) Successful in 4m7s
Test / Hakurei (race detector) (push) Successful in 5m18s
Test / Flake checks (push) Successful in 1m35s
This passes more information allowing for better error handling. This eliminates generic WrapErr from system. Signed-off-by: Ophestra <cat@gensokyo.uk>
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package system
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"slices"
|
|
|
|
"hakurei.app/system/acl"
|
|
)
|
|
|
|
// UpdatePerm appends an ephemeral acl update Op.
|
|
func (sys *I) UpdatePerm(path string, perms ...acl.Perm) *I {
|
|
sys.UpdatePermType(Process, path, perms...)
|
|
|
|
return sys
|
|
}
|
|
|
|
// UpdatePermType appends an acl update Op.
|
|
func (sys *I) UpdatePermType(et Enablement, path string, perms ...acl.Perm) *I {
|
|
sys.lock.Lock()
|
|
defer sys.lock.Unlock()
|
|
|
|
sys.ops = append(sys.ops, &ACL{et, path, perms})
|
|
|
|
return sys
|
|
}
|
|
|
|
type ACL struct {
|
|
et Enablement
|
|
path string
|
|
perms acl.Perms
|
|
}
|
|
|
|
func (a *ACL) Type() Enablement { return a.et }
|
|
|
|
func (a *ACL) apply(sys *I) error {
|
|
msg.Verbose("applying ACL", a)
|
|
return newOpError("acl", acl.Update(a.path, sys.uid, a.perms...), false)
|
|
}
|
|
|
|
func (a *ACL) revert(sys *I, ec *Criteria) error {
|
|
if ec.hasType(a) {
|
|
msg.Verbose("stripping ACL", a)
|
|
err := acl.Update(a.path, sys.uid)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
// the ACL is effectively stripped if the file no longer exists
|
|
msg.Verbosef("target of ACL %s no longer exists", a)
|
|
err = nil
|
|
}
|
|
return newOpError("acl", err, true)
|
|
} else {
|
|
msg.Verbose("skipping ACL", a)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (a *ACL) Is(o Op) bool {
|
|
a0, ok := o.(*ACL)
|
|
return ok && a0 != nil &&
|
|
a.et == a0.et &&
|
|
a.path == a0.path &&
|
|
slices.Equal(a.perms, a0.perms)
|
|
}
|
|
|
|
func (a *ACL) Path() string { return a.path }
|
|
|
|
func (a *ACL) String() string {
|
|
return fmt.Sprintf("%s type: %s path: %q",
|
|
a.perms, TypeString(a.et), a.path)
|
|
}
|