2
2
mirror of https://github.com/octoleo/restic.git synced 2024-09-21 11:29:02 +00:00

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,10 +138,13 @@ func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packe
return errors.Wrap(err, "close tempfile") return errors.Wrap(err, "close tempfile")
} }
// on windows the tempfile is automatically deleted on close
if runtime.GOOS != "windows" {
err = fs.RemoveIfExists(p.tmpfile.Name()) err = fs.RemoveIfExists(p.tmpfile.Name())
if err != nil { if err != nil {
return errors.Wrap(err, "Remove") return errors.Wrap(err, "Remove")
} }
}
// update blobs in the index // update blobs in the index
debug.Log(" updating blobs %v to pack %v", p.Packer.Blobs(), id) debug.Log(" updating blobs %v to pack %v", p.Packer.Blobs(), id)