1package store
2
3import (
4 "log/slog"
5 "os"
6
7 "github.com/mjl-/mox/mlog"
8)
9
10// CloseRemoveTempFile closes and removes f, a file described by descr. Often
11// used in a defer after creating a temporary file.
12func CloseRemoveTempFile(log mlog.Log, f *os.File, descr string) {
13 name := f.Name()
14 err := f.Close()
15 log.Check(err, "closing temporary file", slog.String("kind", descr))
16 err = os.Remove(name)
17 log.Check(err, "removing temporary file", slog.String("kind", descr))
18}
19