mirror of
https://github.com/mjl-/mox.git
synced 2024-12-27 08:53:48 +03:00
5b20cba50a
we don't want external software to include internal details like mlog. slog.Logger is/will be the standard. we still have mlog for its helper functions, and its handler that logs in concise logfmt used by mox. packages that are not meant for reuse still pass around mlog.Log for convenience. we use golang.org/x/exp/slog because we also support the previous Go toolchain version. with the next Go release, we'll switch to the builtin slog.
19 lines
487 B
Go
19 lines
487 B
Go
package store
|
|
|
|
import (
|
|
"os"
|
|
|
|
"golang.org/x/exp/slog"
|
|
|
|
"github.com/mjl-/mox/mlog"
|
|
)
|
|
|
|
// CloseRemoveTempFile closes and removes f, a file described by descr. Often
|
|
// used in a defer after creating a temporary file.
|
|
func CloseRemoveTempFile(log mlog.Log, f *os.File, descr string) {
|
|
name := f.Name()
|
|
err := f.Close()
|
|
log.Check(err, "closing temporary file", slog.String("kind", descr))
|
|
err = os.Remove(name)
|
|
log.Check(err, "removing temporary file", slog.String("kind", descr))
|
|
}
|