diff --git a/cmd/upgrade.go b/cmd/upgrade.go index f2a0dc7..b6bc15e 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -9,13 +9,13 @@ var upgradeCmd = &cobra.Command{ Use: "upgrade", Short: "Upgrade autorestic and restic", Run: func(cmd *cobra.Command, args []string) { - noRestic, _ := cmd.Flags().GetBool("no-restic") - err := bins.Upgrade(!noRestic) + restic, _ := cmd.Flags().GetBool("restic") + err := bins.Upgrade(restic) CheckErr(err) }, } func init() { rootCmd.AddCommand(upgradeCmd) - upgradeCmd.Flags().Bool("no-restic", false, "also update restic") + upgradeCmd.Flags().Bool("restic", true, "also update restic") } diff --git a/internal/bins/bins.go b/internal/bins/bins.go index 87e9488..27c640c 100644 --- a/internal/bins/bins.go +++ b/internal/bins/bins.go @@ -47,11 +47,11 @@ func dlJSON(url string) (GithubRelease, error) { func Uninstall(restic bool) error { if err := os.Remove(path.Join(INSTALL_PATH, "autorestic")); err != nil { - colors.Error.Println(err) + return err } if restic { if err := os.Remove(path.Join(INSTALL_PATH, "restic")); err != nil { - colors.Error.Println(err) + return err } } return nil @@ -79,11 +79,15 @@ func downloadAndInstallAsset(body GithubRelease, name string) error { return err } defer tmp.Close() - tmp.Chmod(0755) - io.Copy(tmp, bz) + if err := tmp.Chmod(0755); err != nil { + return err + } + if _, err := io.Copy(tmp, bz); err != nil { + return err + } to := path.Join(INSTALL_PATH, name) - os.Remove(to) // Delete if current, ignore error if file does not exits. + defer os.Remove(to) // Delete if current, ignore error if file does not exits. if err := os.Rename(tmp.Name(), to); err != nil { return nil } @@ -121,9 +125,11 @@ func Upgrade(restic bool) error { // Upgrade restic if restic { if err := InstallRestic(); err != nil { - colors.Error.Println(err) + return err + } + if err := upgradeRestic(); err != nil { + return err } - upgradeRestic() } // Upgrade self @@ -140,7 +146,9 @@ func Upgrade(restic bool) error { return err } if current.LT(latest) { - downloadAndInstallAsset(body, "autorestic") + if err := downloadAndInstallAsset(body, "autorestic"); err != nil { + return err + } colors.Success.Println("Updated autorestic") } else { colors.Body.Println("Already up to date")