diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-13 01:12:44 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-13 01:12:44 +0900 |
| commit | 763ab27e09b481dbe38099385ec6dd423d8d8ad3 (patch) | |
| tree | b049c7b093c309b7a1bae3661bc9817ca2b323cd /system/tmpfiles.go | |
| parent | bff2a1e748f04c4e7af9b28a03f608f87fcf1a33 (diff) | |
system: remove tmpfiles
This is no longer used.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/tmpfiles.go')
| -rw-r--r-- | system/tmpfiles.go | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/system/tmpfiles.go b/system/tmpfiles.go deleted file mode 100644 index 8d94ceee..00000000 --- a/system/tmpfiles.go +++ /dev/null @@ -1,81 +0,0 @@ -package system - -import ( - "bytes" - "errors" - "fmt" - "io" - "os" - "syscall" - - "hakurei.app/container/check" - "hakurei.app/hst" -) - -// CopyFile reads up to n bytes from src and writes the resulting byte slice to payloadP. -func (sys *I) CopyFile(payloadP *[]byte, src *check.Absolute, cap int, n int64) *I { - buf := new(bytes.Buffer) - buf.Grow(cap) - sys.ops = append(sys.ops, &tmpfileOp{payloadP, src.String(), n, buf}) - return sys -} - -// tmpfileOp implements [I.CopyFile]. -type tmpfileOp struct { - payload *[]byte - src string - - n int64 - buf *bytes.Buffer -} - -func (t *tmpfileOp) Type() hst.Enablement { return Process } - -func (t *tmpfileOp) apply(sys *I) error { - if t.payload == nil { - // this is a misuse of the API; do not return a wrapped error - return errors.New("invalid payload") - } - - sys.msg.Verbose("copying", t) - - if b, err := sys.stat(t.src); err != nil { - return newOpError("tmpfile", err, false) - } else { - if b.IsDir() { - return newOpError("tmpfile", &os.PathError{Op: "stat", Path: t.src, Err: syscall.EISDIR}, false) - } - if s := b.Size(); s > t.n { - return newOpError("tmpfile", &os.PathError{Op: "stat", Path: t.src, Err: syscall.ENOMEM}, false) - } - } - - var r io.ReadCloser - if f, err := sys.open(t.src); err != nil { - return newOpError("tmpfile", err, false) - } else { - r = f - } - if n, err := io.CopyN(t.buf, r, t.n); err != nil { - if !errors.Is(err, io.EOF) { - _ = r.Close() - return newOpError("tmpfile", err, false) - } - sys.msg.Verbosef("copied %d bytes from %q", n, t.src) - } - if err := r.Close(); err != nil { - return newOpError("tmpfile", err, false) - } - - *t.payload = t.buf.Bytes() - return nil -} -func (t *tmpfileOp) revert(*I, *Criteria) error { t.buf.Reset(); return nil } - -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 *tmpfileOp) Path() string { return t.src } -func (t *tmpfileOp) String() string { return fmt.Sprintf("up to %d bytes from %q", t.n, t.src) } |
