From 34e67e351039ee9c88365bd6504a9d388fff39de Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 20 Jan 2023 23:13:04 +0100 Subject: [PATCH] self-update: Fix handling of `--output` on windows The code always assumed that the upgrade happens in place. Thus writing the upgrade to a separate file fails, when trying to remove the file stored at that location. --- internal/selfupdate/download_windows.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/selfupdate/download_windows.go b/internal/selfupdate/download_windows.go index 4f2797385..50480eab6 100644 --- a/internal/selfupdate/download_windows.go +++ b/internal/selfupdate/download_windows.go @@ -7,11 +7,18 @@ import ( "fmt" "os" "path/filepath" + + "github.com/restic/restic/internal/errors" ) // Rename (rather than remove) the running version. The running binary will be locked // on Windows and cannot be removed while still executing. func removeResticBinary(dir, target string) error { + // nothing to do if the target does not exist + if _, err := os.Stat(target); errors.Is(err, os.ErrNotExist) { + return nil + } + backup := filepath.Join(dir, filepath.Base(target)+".bak") if _, err := os.Stat(backup); err == nil { _ = os.Remove(backup)