fix(defrag): close temp file in case of error

Signed-off-by: Thomas Gosteli <thomas.gosteli@protonmail.ch>
This commit is contained in:
Thomas Gosteli
2024-11-07 10:19:15 +01:00
parent 4ad9261194
commit a19d4087cc

View File

@ -499,6 +499,15 @@ func (b *backend) defrag() error {
tdbp := temp.Name()
tmpdb, err := bolt.Open(tdbp, 0600, &options)
if err != nil {
temp.Close()
if err := os.Remove(temp.Name()); err != nil && b.lg != nil {
b.lg.Error(
"failed to remove temporary file",
zap.String("path", temp.Name()),
zap.Error(err),
)
}
return err
}