Skip to content

Fix macosx ventura updater #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed diff-based updates
  • Loading branch information
cmaglie committed Feb 14, 2023
commit 342e24368dd52858454a2685aad705e51fa820c6
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/gin-gonic/gin v1.8.1
github.com/go-ini/ini v1.62.0
github.com/googollee/go-socket.io v0.0.0-20181101151912-c8aeb1ed9b49
github.com/kr/binarydist v0.1.0
github.com/mattn/go-shellwords v1.0.12
github.com/mitchellh/go-homedir v1.1.0
github.com/oleksandr/bonjour v0.0.0-20210301155756-30f43c61b915
Expand Down Expand Up @@ -56,6 +55,7 @@ require (
github.com/juju/errors v0.0.0-20200330140219-3fe23663418f // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/klauspost/compress v1.15.13 // indirect
github.com/kr/binarydist v0.1.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
Expand Down
2 changes: 1 addition & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

func updateHandler(c *gin.Context) {
restartPath, err := updater.CheckForUpdates(version, *updateURL, *updateURL, *appName)
restartPath, err := updater.CheckForUpdates(version, *updateURL, *appName)
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
Expand Down
4 changes: 2 additions & 2 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func Start(src string) string {

// CheckForUpdates checks if there is a new version of the binary available and
// if so downloads it.
func CheckForUpdates(currentVersion string, updateAPIURL, updateBinURL string, cmdName string) (string, error) {
return checkForUpdates(currentVersion, updateAPIURL, updateBinURL, cmdName)
func CheckForUpdates(currentVersion string, updateURL string, cmdName string) (string, error) {
return checkForUpdates(currentVersion, updateURL, cmdName)
}

const (
Expand Down
6 changes: 3 additions & 3 deletions updater/updater_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func start(src string) string {
return ""
}

func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, cmdName string) (string, error) {
func checkForUpdates(currentVersion string, updateURL string, cmdName string) (string, error) {
executablePath, err := os.Executable()
if err != nil {
return "", fmt.Errorf("could not app path: %w", err)
Expand All @@ -70,7 +70,7 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
}

// Fetch information about updates
info, err := fetchInfo(updateAPIURL, cmdName)
info, err := fetchInfo(updateURL, cmdName)
if err != nil {
return "", err
}
Expand All @@ -88,7 +88,7 @@ func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, c
defer tmp.RemoveAll()

// Download the update.
downloadURL := updateBinURL + cmdName + "/" + info.Version + "/ArduinoCreateAgent.app_notarized.zip"
downloadURL := updateURL + cmdName + "/" + info.Version + "/ArduinoCreateAgent.app_notarized.zip"
logrus.WithField("url", downloadURL).Info("Downloading update")
download, err := fetch(downloadURL)
if err != nil {
Expand Down
70 changes: 13 additions & 57 deletions updater/updater_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"path/filepath"
"strings"

"github.com/kr/binarydist"
log "github.com/sirupsen/logrus"
"gopkg.in/inconshreveable/go-update.v0"
)
Expand Down Expand Up @@ -60,7 +59,6 @@ import (
//

var errHashMismatch = errors.New("new file hash mismatch after patch")
var errDiffURLUndefined = errors.New("DiffURL is not defined, I cannot fetch and apply patch, reverting to full bin")
var up = update.New()

func start(src string) string {
Expand All @@ -81,16 +79,14 @@ func start(src string) string {
return ""
}

func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, cmdName string) (string, error) {
func checkForUpdates(currentVersion string, updateURL string, cmdName string) (string, error) {
path, err := os.Executable()
if err != nil {
return "", err
}
var up = &Updater{
CurrentVersion: currentVersion,
APIURL: updateAPIURL,
BinURL: updateBinURL,
DiffURL: "",
UpdateURL: updateURL,
Dir: "update/",
CmdName: cmdName,
}
Expand Down Expand Up @@ -139,9 +135,7 @@ func removeTempSuffixFromPath(path string) string {
//
// updater := &selfupdate.Updater{
// CurrentVersion: version,
// ApiURL: "http://updates.yourdomain.com/",
// BinURL: "http://updates.yourdownmain.com/",
// DiffURL: "http://updates.yourdomain.com/",
// UpdateURL: "http://updates.yourdomain.com/",
// Dir: "update/",
// CmdName: "myapp", // app name
// }
Expand All @@ -150,10 +144,8 @@ func removeTempSuffixFromPath(path string) string {
// }
type Updater struct {
CurrentVersion string // Currently running version.
APIURL string // Base URL for API requests (json files).
UpdateURL string // Base URL for API requests (json files).
CmdName string // Command name is appended to the ApiURL like http://apiurl/CmdName/. This represents one binary.
BinURL string // Base URL for full binary downloads.
DiffURL string // Base URL for diff downloads.
Dir string // Directory to store selfupdate state.
Info *availableUpdateInfo // Information about the available update.
}
Expand Down Expand Up @@ -183,31 +175,6 @@ func verifySha(bin []byte, sha []byte) bool {
return bytes.Equal(h.Sum(nil), sha)
}

func (u *Updater) fetchAndApplyPatch(old io.Reader) ([]byte, error) {
if u.DiffURL == "" {
return nil, errDiffURLUndefined
}
r, err := fetch(u.DiffURL + u.CmdName + "/" + u.CurrentVersion + "/" + u.Info.Version + "/" + plat)
if err != nil {
return nil, err
}
defer r.Close()
var buf bytes.Buffer
err = binarydist.Patch(old, &buf, r)
return buf.Bytes(), err
}

func (u *Updater) fetchAndVerifyPatch(old io.Reader) ([]byte, error) {
bin, err := u.fetchAndApplyPatch(old)
if err != nil {
return nil, err
}
if !verifySha(bin, u.Info.Sha256) {
return nil, errHashMismatch
}
return bin, nil
}

func (u *Updater) fetchAndVerifyFullBin() ([]byte, error) {
bin, err := u.fetchBin()
if err != nil {
Expand All @@ -221,7 +188,7 @@ func (u *Updater) fetchAndVerifyFullBin() ([]byte, error) {
}

func (u *Updater) fetchBin() ([]byte, error) {
r, err := fetch(u.BinURL + u.CmdName + "/" + u.Info.Version + "/" + plat + ".gz")
r, err := fetch(u.UpdateURL + u.CmdName + "/" + u.Info.Version + "/" + plat + ".gz")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -258,7 +225,7 @@ func (u *Updater) update() error {
}
defer old.Close()

info, err := fetchInfo(u.APIURL, u.CmdName)
info, err := fetchInfo(u.UpdateURL, u.CmdName)
if err != nil {
log.Println(err)
return err
Expand All @@ -267,26 +234,15 @@ func (u *Updater) update() error {
if u.Info.Version == u.CurrentVersion {
return nil
}
bin, err := u.fetchAndVerifyPatch(old)
if err != nil {
switch err {
case errHashMismatch:
log.Println("update: hash mismatch from patched binary")
case errDiffURLUndefined:
log.Println("update: ", err)
default:
log.Println("update: patching binary, ", err)
}

bin, err = u.fetchAndVerifyFullBin()
if err != nil {
if err == errHashMismatch {
log.Println("update: hash mismatch from full binary")
} else {
log.Println("update: fetching full binary,", err)
}
return err
bin, err := u.fetchAndVerifyFullBin()
if err != nil {
if err == errHashMismatch {
log.Println("update: hash mismatch from full binary")
} else {
log.Println("update: fetching full binary,", err)
}
return err
}

// close the old binary before installing because on windows
Expand Down