system: document I methods
Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
ff30a5ab5d
commit
a9986aab6a
@ -1,3 +1,4 @@
|
|||||||
|
// Package system provides tools for safely interacting with the operating system.
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -14,6 +15,7 @@ const (
|
|||||||
Process = Enablement(ELen + 1)
|
Process = Enablement(ELen + 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Criteria specifies types of Op to revert.
|
||||||
type Criteria struct {
|
type Criteria struct {
|
||||||
*Enablements
|
*Enablements
|
||||||
}
|
}
|
||||||
@ -42,6 +44,7 @@ type Op interface {
|
|||||||
String() string
|
String() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TypeString returns the string representation of a type stored as an [Enablement].
|
||||||
func TypeString(e Enablement) string {
|
func TypeString(e Enablement) string {
|
||||||
switch e {
|
switch e {
|
||||||
case User:
|
case User:
|
||||||
@ -64,6 +67,7 @@ func New(uid int) (sys *I) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An I provides indirect bulk operating system interaction. I must not be copied.
|
||||||
type I struct {
|
type I struct {
|
||||||
uid int
|
uid int
|
||||||
ops []Op
|
ops []Op
|
||||||
@ -91,6 +95,7 @@ func (sys *I) wrapErrSuffix(err error, a ...any) error {
|
|||||||
return sys.wrapErr(err, append(a, err)...)
|
return sys.wrapErr(err, append(a, err)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Equal returns whether all [Op] instances held by v is identical to that of sys.
|
||||||
func (sys *I) Equal(v *I) bool {
|
func (sys *I) Equal(v *I) bool {
|
||||||
if v == nil || sys.uid != v.uid || len(sys.ops) != len(v.ops) {
|
if v == nil || sys.uid != v.uid || len(sys.ops) != len(v.ops) {
|
||||||
return false
|
return false
|
||||||
@ -105,6 +110,8 @@ func (sys *I) Equal(v *I) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Commit applies all [Op] held by [I] and reverts successful [Op] on first error encountered.
|
||||||
|
// Commit must not be called more than once.
|
||||||
func (sys *I) Commit(ctx context.Context) error {
|
func (sys *I) Commit(ctx context.Context) error {
|
||||||
sys.lock.Lock()
|
sys.lock.Lock()
|
||||||
defer sys.lock.Unlock()
|
defer sys.lock.Unlock()
|
||||||
@ -141,6 +148,7 @@ func (sys *I) Commit(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Revert reverts all [Op] meeting [Criteria] held by [I].
|
||||||
func (sys *I) Revert(ec *Criteria) error {
|
func (sys *I) Revert(ec *Criteria) error {
|
||||||
sys.lock.Lock()
|
sys.lock.Lock()
|
||||||
defer sys.lock.Unlock()
|
defer sys.lock.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user