diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-08 03:22:10 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-08 03:22:10 +0900 |
| commit | da2b9c01ceac2d55c271de46d7d18e5b3f19b89b (patch) | |
| tree | 94cf9dadbe7b49eef36b2b57b799840496b671f1 /system/tmpfiles.go | |
| parent | 323d132c40a74c5ac7a91731a0c43def2a8be7f1 (diff) | |
system/tmpfiles: do not fail for smaller files
The limit is meant to be an upper bound. Handle EOF and print verbose message for it instead of failing.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/tmpfiles.go')
| -rw-r--r-- | system/tmpfiles.go | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/system/tmpfiles.go b/system/tmpfiles.go index bd865d44..d2a6c93a 100644 --- a/system/tmpfiles.go +++ b/system/tmpfiles.go @@ -28,15 +28,15 @@ type tmpfileOp struct { func (t *tmpfileOp) Type() Enablement { return Process } -func (t *tmpfileOp) apply(*I) error { - msg.Verbose("copying", t) - +func (t *tmpfileOp) apply(sys *I) error { if t.payload == nil { - // this is a misuse of the API; do not return an error message + // this is a misuse of the API; do not return a wrapped error return errors.New("invalid payload") } - if b, err := os.Stat(t.src); err != nil { + sys.verbose("copying", t) + + if b, err := sys.stat(t.src); err != nil { return newOpError("tmpfile", err, false) } else { if b.IsDir() { @@ -47,9 +47,20 @@ func (t *tmpfileOp) apply(*I) error { } } - if f, err := os.Open(t.src); err != nil { + var r io.ReadCloser + if f, err := sys.open(t.src); err != nil { return newOpError("tmpfile", err, false) - } else if _, err = io.CopyN(t.buf, f, t.n); err != nil { + } 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.verbosef("copied %d bytes from %q", n, t.src) + } + if err := r.Close(); err != nil { return newOpError("tmpfile", err, false) } |
