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
Always complete the old auto-upgrade procedure
This is required for clients upgrading from versions <=1.2.7
  • Loading branch information
cmaglie committed Feb 14, 2023
commit 1c0d4138fd9c8c2540e0f295491ee3b525252083
33 changes: 33 additions & 0 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"runtime"
"strings"

log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -77,3 +80,33 @@ func fetch(url string) (io.ReadCloser, error) {
}
return resp.Body, nil
}

// addTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe")
func addTempSuffixToPath(path string) string {
if filepath.Ext(path) == "exe" {
path = strings.Replace(path, ".exe", "-temp.exe", -1)
} else {
path = path + "-temp"
}

return path
}

// removeTempSuffixFromPath removes "-temp" suffix from the path to an executable file (a "-temp.exe" extension is replaced with ".exe")
func removeTempSuffixFromPath(path string) string {
return strings.Replace(path, "-temp", "", -1)
}

func copyExe(from, to string) error {
data, err := os.ReadFile(from)
if err != nil {
log.Println("Cannot read file: ", from)
return err
}
err = os.WriteFile(to, data, 0755)
if err != nil {
log.Println("Cannot write file: ", to)
return err
}
return nil
}
17 changes: 17 additions & 0 deletions updater/updater_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,30 @@ import (
"io"
"os"
"runtime"
"strings"

"github.com/arduino/go-paths-helper"
"github.com/codeclysm/extract/v3"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)

func start(src string) string {
if strings.Contains(src, "-temp") {
// This is required to transition from the previous auto-update system to the new one.
// Updating from version <=1.2.7 will produce the `ArduinoCreateAgent-temp` file and we should
// complete the upgrade by copying the `ArduinoCreateAgent-temp` executable back to the original.
//
// This procedure will be automatically skipped starting from version >1.2.7.

newPath := removeTempSuffixFromPath(src)
if err := copyExe(src, newPath); err != nil {
log.Println("Copy error: ", err)
panic(err)
}
return newPath
}

return ""
}

Expand Down
30 changes: 0 additions & 30 deletions updater/updater_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,6 @@ func checkForUpdates(currentVersion string, updateURL string, cmdName string) (s
return addTempSuffixToPath(path), nil
}

func copyExe(from, to string) error {
data, err := os.ReadFile(from)
if err != nil {
log.Println("Cannot read file: ", from)
return err
}
err = os.WriteFile(to, data, 0755)
if err != nil {
log.Println("Cannot write file: ", to)
return err
}
return nil
}

// addTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe")
func addTempSuffixToPath(path string) string {
if filepath.Ext(path) == "exe" {
path = strings.Replace(path, ".exe", "-temp.exe", -1)
} else {
path = path + "-temp"
}

return path
}

// removeTempSuffixFromPath removes "-temp" suffix from the path to an executable file (a "-temp.exe" extension is replaced with ".exe")
func removeTempSuffixFromPath(path string) string {
return strings.Replace(path, "-temp", "", -1)
}

// Updater is the configuration and runtime data for doing an update.
//
// Note that ApiURL, BinURL and DiffURL should have the same value if all files are available at the same location.
Expand Down