aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/op.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-25 04:42:30 +0900
committerOphestra <cat@gensokyo.uk>2025-03-25 04:42:30 +0900
commitec5e91b8c97f02707a70a789ba4af84d51394ea5 (patch)
tree45f05e1315063936741ddafde8b5f95338315b54 /system/op.go
parentee51320abfeafabecd42659a88af9dfd44308a3a (diff)
system: optimise string formatting
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/op.go')
-rw-r--r--system/op.go34
1 files changed, 23 insertions, 11 deletions
diff --git a/system/op.go b/system/op.go
index 3c334b07..10e95c1a 100644
--- a/system/op.go
+++ b/system/op.go
@@ -5,28 +5,29 @@ import (
"context"
"errors"
"log"
+ "strings"
"sync"
)
const (
// User type is reverted at final launcher exit.
- User = Enablement(ELen)
+ User = EM << iota
// Process type is unconditionally reverted on exit.
- Process = Enablement(ELen + 1)
+ Process
+
+ CM
)
// Criteria specifies types of Op to revert.
-type Criteria struct {
- *Enablements
-}
+type Criteria Enablement
func (ec *Criteria) hasType(o Op) bool {
// nil criteria: revert everything except User
- if ec.Enablements == nil {
+ if ec == nil {
return o.Type() != User
}
- return ec.Has(o.Type())
+ return Enablement(*ec)&o.Type() != 0
}
// Op is a reversible system operation.
@@ -48,11 +49,22 @@ type Op interface {
func TypeString(e Enablement) string {
switch e {
case User:
- return "User"
+ return "user"
case Process:
- return "Process"
+ return "process"
default:
- return e.String()
+ buf := new(strings.Builder)
+ buf.Grow(48)
+ if v := e &^ User &^ Process; v != 0 {
+ buf.WriteString(v.String())
+ }
+
+ for i := User; i < CM; i <<= 1 {
+ if e&i != 0 {
+ buf.WriteString(", " + TypeString(i))
+ }
+ }
+ return strings.TrimPrefix(buf.String(), ", ")
}
}
@@ -110,7 +122,7 @@ func (sys *I) Commit(ctx context.Context) error {
if sp != nil {
// rollback partial commit
msg.Verbosef("commit faulted after %d ops, rolling back partial commit", len(sp.ops))
- if err := sp.Revert(&Criteria{nil}); err != nil {
+ if err := sp.Revert(nil); err != nil {
log.Println("errors returned reverting partial commit:", err)
}
}