From ae7e51382a1709ea9bb494c547298e5c0d202eaa Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 9 May 2022 22:43:26 +0200 Subject: [PATCH] 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. --- internal/repository/packer_manager.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/repository/packer_manager.go b/internal/repository/packer_manager.go index 73c0d5240..7347a0e1a 100644 --- a/internal/repository/packer_manager.go +++ b/internal/repository/packer_manager.go @@ -5,6 +5,7 @@ import ( "hash" "io" "os" + "runtime" "sync" "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") } - err = fs.RemoveIfExists(p.tmpfile.Name()) - if err != nil { - return errors.Wrap(err, "Remove") + // on windows the tempfile is automatically deleted on close + if runtime.GOOS != "windows" { + err = fs.RemoveIfExists(p.tmpfile.Name()) + if err != nil { + return errors.Wrap(err, "Remove") + } } // update blobs in the index