aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/tmpfiles.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-02 04:54:34 +0900
committerOphestra <cat@gensokyo.uk>2025-09-02 04:54:34 +0900
commit6f719bc3c19d56279d2d76d3bcf8fb66ace2d2fb (patch)
tree6e9e84fd6f382fa823c87a70a0df0284dc127250 /system/tmpfiles.go
parent1b5d20a39b2c5720d83a8eaf3d2227deb46a7c0d (diff)
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>
Diffstat (limited to 'system/tmpfiles.go')
-rw-r--r--system/tmpfiles.go30
1 files changed, 13 insertions, 17 deletions
diff --git a/system/tmpfiles.go b/system/tmpfiles.go
index 44d170f6..2850ba22 100644
--- a/system/tmpfiles.go
+++ b/system/tmpfiles.go
@@ -9,20 +9,16 @@ import (
"syscall"
)
-// CopyFile registers an Op that copies from src.
-// A buffer is initialised with size cap and the Op faults if bytes read exceed n.
+// CopyFile appends [TmpfileOp] to [I].
func (sys *I) CopyFile(payload *[]byte, src string, cap int, n int64) *I {
buf := new(bytes.Buffer)
buf.Grow(cap)
-
- sys.lock.Lock()
- sys.ops = append(sys.ops, &Tmpfile{payload, src, n, buf})
- sys.lock.Unlock()
-
+ sys.ops = append(sys.ops, &TmpfileOp{payload, src, n, buf})
return sys
}
-type Tmpfile struct {
+// TmpfileOp reads up to n bytes from src and writes the resulting byte slice to payload.
+type TmpfileOp struct {
payload *[]byte
src string
@@ -30,8 +26,8 @@ type Tmpfile struct {
buf *bytes.Buffer
}
-func (t *Tmpfile) Type() Enablement { return Process }
-func (t *Tmpfile) apply(*I) error {
+func (t *TmpfileOp) Type() Enablement { return Process }
+func (t *TmpfileOp) apply(*I) error {
msg.Verbose("copying", t)
if t.payload == nil {
@@ -59,12 +55,12 @@ func (t *Tmpfile) apply(*I) error {
*t.payload = t.buf.Bytes()
return nil
}
-func (t *Tmpfile) revert(*I, *Criteria) error { t.buf.Reset(); return nil }
+func (t *TmpfileOp) revert(*I, *Criteria) error { t.buf.Reset(); return nil }
-func (t *Tmpfile) Is(o Op) bool {
- t0, ok := o.(*Tmpfile)
- return ok && t0 != nil &&
- t.src == t0.src && t.n == t0.n
+func (t *TmpfileOp) Is(o Op) bool {
+ target, ok := o.(*TmpfileOp)
+ return ok && t != nil && target != nil &&
+ t.src == target.src && t.n == target.n
}
-func (t *Tmpfile) Path() string { return t.src }
-func (t *Tmpfile) String() string { return fmt.Sprintf("up to %d bytes from %q", t.n, t.src) }
+func (t *TmpfileOp) Path() string { return t.src }
+func (t *TmpfileOp) String() string { return fmt.Sprintf("up to %d bytes from %q", t.n, t.src) }