aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/system/op.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-17 17:54:28 +0900
committerOphestra <cat@gensokyo.uk>2025-02-17 18:17:55 +0900
commitb1e1d5627e6532ec719c761846d7f38fe93fcadd (patch)
tree2a308de9ee6a53b536ad00877158dc959e9cdea4 /internal/system/op.go
parent3ae2ab652e9cd1d6250dbde8ae0f9b9fe90afc72 (diff)
system: wrap console output functions
This eliminates all fmsg imports from internal/system. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/system/op.go')
-rw-r--r--internal/system/op.go35
1 files changed, 26 insertions, 9 deletions
diff --git a/internal/system/op.go b/internal/system/op.go
index 42f93d43..0e421aec 100644
--- a/internal/system/op.go
+++ b/internal/system/op.go
@@ -5,8 +5,6 @@ import (
"errors"
"log"
"sync"
-
- "git.gensokyo.uk/security/fortify/internal/fmsg"
)
const (
@@ -55,19 +53,42 @@ func TypeString(e Enablement) string {
}
}
+// New initialises sys with no-op verbose functions.
+func New(uid int) (sys *I) {
+ sys = new(I)
+ sys.uid = uid
+ sys.IsVerbose = func() bool { return false }
+ sys.Verbose = func(...any) {}
+ sys.Verbosef = func(string, ...any) {}
+ sys.WrapErr = func(err error, _ ...any) error { return err }
+ return
+}
+
type I struct {
uid int
ops []Op
ctx context.Context
+ IsVerbose func() bool
+ Verbose func(v ...any)
+ Verbosef func(format string, v ...any)
+ WrapErr func(err error, a ...any) error
+
// whether sys has been reverted
state bool
lock sync.Mutex
}
-func (sys *I) UID() int {
- return sys.uid
+func (sys *I) UID() int { return sys.uid }
+func (sys *I) println(v ...any) { sys.Verbose(v...) }
+func (sys *I) printf(format string, v ...any) { sys.Verbosef(format, v...) }
+func (sys *I) wrapErr(err error, a ...any) error { return sys.WrapErr(err, a...) }
+func (sys *I) wrapErrSuffix(err error, a ...any) error {
+ if err == nil {
+ return nil
+ }
+ return sys.wrapErr(err, append(a, err)...)
}
func (sys *I) Equal(v *I) bool {
@@ -99,7 +120,7 @@ func (sys *I) Commit(ctx context.Context) error {
// sp is set to nil when all ops are applied
if sp != nil {
// rollback partial commit
- fmsg.Verbosef("commit faulted after %d ops, rolling back partial commit", len(sp.ops))
+ sys.printf("commit faulted after %d ops, rolling back partial commit", len(sp.ops))
if err := sp.Revert(&Criteria{nil}); err != nil {
log.Println("errors returned reverting partial commit:", err)
}
@@ -139,7 +160,3 @@ func (sys *I) Revert(ec *Criteria) error {
// errors.Join filters nils
return errors.Join(errs...)
}
-
-func New(uid int) *I {
- return &I{uid: uid}
-}