From 80ed863aab455e3843136c69c3639d23cb4fd720 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 21 Jul 2024 15:00:34 +0200 Subject: [PATCH] repository: remove redundant cleanup code The temp files used by the packer manager are either delete after creation (unix) or marked as delete on close (windows). Thus, no explicit cleanup is necessary. --- internal/fs/file.go | 9 --------- internal/repository/packer_manager.go | 9 --------- 2 files changed, 18 deletions(-) diff --git a/internal/fs/file.go b/internal/fs/file.go index 1071f4e87..356b466c3 100644 --- a/internal/fs/file.go +++ b/internal/fs/file.go @@ -88,15 +88,6 @@ func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) { return os.OpenFile(fixpath(name), flag, perm) } -// RemoveIfExists removes a file, returning no error if it does not exist. -func RemoveIfExists(filename string) error { - err := os.Remove(filename) - if err != nil && os.IsNotExist(err) { - err = nil - } - return err -} - // Chtimes changes the access and modification times of the named file, // similar to the Unix utime() or utimes() functions. // diff --git a/internal/repository/packer_manager.go b/internal/repository/packer_manager.go index 8dd8f71c1..731ad9a6a 100644 --- a/internal/repository/packer_manager.go +++ b/internal/repository/packer_manager.go @@ -6,7 +6,6 @@ import ( "crypto/sha256" "io" "os" - "runtime" "sync" "github.com/restic/restic/internal/backend" @@ -186,14 +185,6 @@ func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *packe 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()) - if err != nil { - return errors.WithStack(err) - } - } - // update blobs in the index debug.Log(" updating blobs %v to pack %v", p.Packer.Blobs(), id) r.idx.StorePack(id, p.Packer.Blobs())