diff options
Diffstat (limited to 'system/tmpfiles.go')
| -rw-r--r-- | system/tmpfiles.go | 30 |
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) } |
