lib/upgrade: Cleanup failed upgrades (fixes #3500, fixes #3530)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3535
This commit is contained in:
Audrius Butkevicius 2016-08-23 06:53:39 +00:00 committed by Jakob Borg
parent be38c2111f
commit 76b903b2e0

View File

@ -198,6 +198,7 @@ func upgradeToURL(archiveName, binary string, url string) error {
if err != nil {
return err
}
defer os.Remove(fname)
old := binary + ".old"
os.Remove(old)
@ -205,7 +206,11 @@ func upgradeToURL(archiveName, binary string, url string) error {
if err != nil {
return err
}
return os.Rename(fname, binary)
if os.Rename(fname, binary); err != nil {
os.Rename(old, binary)
return err
}
return nil
}
func readRelease(archiveName, dir, url string) (string, error) {