Fix error on temp file deletion on windows

Apparently it can take a moment between closing a tempfile marked as
DELETE_ON_CLOSE and it actually being deleted. During that time the file
is inaccessible. Thus just skip deleting the temp file on windows.
This commit is contained in:
Michael Eischer 2022-05-09 22:43:26 +02:00
parent ab49c14621
commit ae7e51382a

View file

@ -5,6 +5,7 @@ import (
"hash" "hash"
"io" "io"
"os" "os"
"runtime"
"sync" "sync"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
@ -137,9 +138,12 @@ func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packe
return errors.Wrap(err, "close tempfile") return errors.Wrap(err, "close tempfile")
} }
err = fs.RemoveIfExists(p.tmpfile.Name()) // on windows the tempfile is automatically deleted on close
if err != nil { if runtime.GOOS != "windows" {
return errors.Wrap(err, "Remove") err = fs.RemoveIfExists(p.tmpfile.Name())
if err != nil {
return errors.Wrap(err, "Remove")
}
} }
// update blobs in the index // update blobs in the index