2023-11-01 19:55:40 +03:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2023-12-05 15:35:58 +03:00
|
|
|
"golang.org/x/exp/slog"
|
|
|
|
|
2023-11-01 19:55:40 +03:00
|
|
|
"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.
|
2023-12-05 15:35:58 +03:00
|
|
|
func CloseRemoveTempFile(log mlog.Log, f *os.File, descr string) {
|
2023-11-01 19:55:40 +03:00
|
|
|
name := f.Name()
|
|
|
|
err := f.Close()
|
2023-12-05 15:35:58 +03:00
|
|
|
log.Check(err, "closing temporary file", slog.String("kind", descr))
|
2023-11-01 19:55:40 +03:00
|
|
|
err = os.Remove(name)
|
2023-12-05 15:35:58 +03:00
|
|
|
log.Check(err, "removing temporary file", slog.String("kind", descr))
|
2023-11-01 19:55:40 +03:00
|
|
|
}
|