forked from TrueCloudLab/restic
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.
This commit is contained in:
parent
0f398b82e3
commit
34e67e3510
1 changed files with 7 additions and 0 deletions
|
@ -7,11 +7,18 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/restic/restic/internal/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Rename (rather than remove) the running version. The running binary will be locked
|
// Rename (rather than remove) the running version. The running binary will be locked
|
||||||
// on Windows and cannot be removed while still executing.
|
// on Windows and cannot be removed while still executing.
|
||||||
func removeResticBinary(dir, target string) error {
|
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")
|
backup := filepath.Join(dir, filepath.Base(target)+".bak")
|
||||||
if _, err := os.Stat(backup); err == nil {
|
if _, err := os.Stat(backup); err == nil {
|
||||||
_ = os.Remove(backup)
|
_ = os.Remove(backup)
|
||||||
|
|
Loading…
Reference in a new issue