fix auto update

This commit is contained in:
2021-04-20 23:26:57 +02:00
parent ea82fea8e1
commit 873170c6d1
4 changed files with 25 additions and 12 deletions

View File

@@ -72,14 +72,21 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
// Uncompress
bz := bzip2.NewReader(resp.Body)
// Save binary
file, err := os.Create(path.Join(INSTALL_PATH, name))
// Save to tmp
// Linux does not support overwriting the file that is currently being overwritten, but it can be deleted and a new one moved in its place.
tmp, err := ioutil.TempFile(os.TempDir(), "autorestic-")
if err != nil {
return err
}
file.Chmod(0755)
defer file.Close()
io.Copy(file, bz)
defer tmp.Close()
tmp.Chmod(0755)
io.Copy(tmp, bz)
to := path.Join(INSTALL_PATH, name)
os.Remove(to) // Delete if current, ignore error if file does not exits.
if err := os.Rename(tmp.Name(), to); err != nil {
return nil
}
colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH)
return nil

View File

@@ -12,7 +12,7 @@ import (
"github.com/spf13/viper"
)
const VERSION = "1.0.2"
const VERSION = "1.0.3"
var CI bool = false
var VERBOSE bool = false