Skip to content

Commit 342e243

Browse files
committed
Removed diff-based updates
1 parent d8e770c commit 342e243

File tree

5 files changed

+20
-64
lines changed

5 files changed

+20
-64
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/gin-gonic/gin v1.8.1
1313
github.com/go-ini/ini v1.62.0
1414
github.com/googollee/go-socket.io v0.0.0-20181101151912-c8aeb1ed9b49
15-
github.com/kr/binarydist v0.1.0
1615
github.com/mattn/go-shellwords v1.0.12
1716
github.com/mitchellh/go-homedir v1.1.0
1817
github.com/oleksandr/bonjour v0.0.0-20210301155756-30f43c61b915
@@ -56,6 +55,7 @@ require (
5655
github.com/juju/errors v0.0.0-20200330140219-3fe23663418f // indirect
5756
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
5857
github.com/klauspost/compress v1.15.13 // indirect
58+
github.com/kr/binarydist v0.1.0 // indirect
5959
github.com/kr/fs v0.1.0 // indirect
6060
github.com/leodido/go-urn v1.2.1 // indirect
6161
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect

update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
)
3636

3737
func updateHandler(c *gin.Context) {
38-
restartPath, err := updater.CheckForUpdates(version, *updateURL, *updateURL, *appName)
38+
restartPath, err := updater.CheckForUpdates(version, *updateURL, *appName)
3939
if err != nil {
4040
c.JSON(500, gin.H{"error": err.Error()})
4141
return

updater/updater.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func Start(src string) string {
3636

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

4343
const (

updater/updater_darwin.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func start(src string) string {
5555
return ""
5656
}
5757

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

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

9090
// Download the update.
91-
downloadURL := updateBinURL + cmdName + "/" + info.Version + "/ArduinoCreateAgent.app_notarized.zip"
91+
downloadURL := updateURL + cmdName + "/" + info.Version + "/ArduinoCreateAgent.app_notarized.zip"
9292
logrus.WithField("url", downloadURL).Info("Downloading update")
9393
download, err := fetch(downloadURL)
9494
if err != nil {

updater/updater_default.go

+13-57
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"path/filepath"
2929
"strings"
3030

31-
"github.com/kr/binarydist"
3231
log "github.com/sirupsen/logrus"
3332
"gopkg.in/inconshreveable/go-update.v0"
3433
)
@@ -60,7 +59,6 @@ import (
6059
//
6160

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

6664
func start(src string) string {
@@ -81,16 +79,14 @@ func start(src string) string {
8179
return ""
8280
}
8381

84-
func checkForUpdates(currentVersion string, updateAPIURL, updateBinURL string, cmdName string) (string, error) {
82+
func checkForUpdates(currentVersion string, updateURL string, cmdName string) (string, error) {
8583
path, err := os.Executable()
8684
if err != nil {
8785
return "", err
8886
}
8987
var up = &Updater{
9088
CurrentVersion: currentVersion,
91-
APIURL: updateAPIURL,
92-
BinURL: updateBinURL,
93-
DiffURL: "",
89+
UpdateURL: updateURL,
9490
Dir: "update/",
9591
CmdName: cmdName,
9692
}
@@ -139,9 +135,7 @@ func removeTempSuffixFromPath(path string) string {
139135
//
140136
// updater := &selfupdate.Updater{
141137
// CurrentVersion: version,
142-
// ApiURL: "http://updates.yourdomain.com/",
143-
// BinURL: "http://updates.yourdownmain.com/",
144-
// DiffURL: "http://updates.yourdomain.com/",
138+
// UpdateURL: "http://updates.yourdomain.com/",
145139
// Dir: "update/",
146140
// CmdName: "myapp", // app name
147141
// }
@@ -150,10 +144,8 @@ func removeTempSuffixFromPath(path string) string {
150144
// }
151145
type Updater struct {
152146
CurrentVersion string // Currently running version.
153-
APIURL string // Base URL for API requests (json files).
147+
UpdateURL string // Base URL for API requests (json files).
154148
CmdName string // Command name is appended to the ApiURL like http://apiurl/CmdName/. This represents one binary.
155-
BinURL string // Base URL for full binary downloads.
156-
DiffURL string // Base URL for diff downloads.
157149
Dir string // Directory to store selfupdate state.
158150
Info *availableUpdateInfo // Information about the available update.
159151
}
@@ -183,31 +175,6 @@ func verifySha(bin []byte, sha []byte) bool {
183175
return bytes.Equal(h.Sum(nil), sha)
184176
}
185177

186-
func (u *Updater) fetchAndApplyPatch(old io.Reader) ([]byte, error) {
187-
if u.DiffURL == "" {
188-
return nil, errDiffURLUndefined
189-
}
190-
r, err := fetch(u.DiffURL + u.CmdName + "/" + u.CurrentVersion + "/" + u.Info.Version + "/" + plat)
191-
if err != nil {
192-
return nil, err
193-
}
194-
defer r.Close()
195-
var buf bytes.Buffer
196-
err = binarydist.Patch(old, &buf, r)
197-
return buf.Bytes(), err
198-
}
199-
200-
func (u *Updater) fetchAndVerifyPatch(old io.Reader) ([]byte, error) {
201-
bin, err := u.fetchAndApplyPatch(old)
202-
if err != nil {
203-
return nil, err
204-
}
205-
if !verifySha(bin, u.Info.Sha256) {
206-
return nil, errHashMismatch
207-
}
208-
return bin, nil
209-
}
210-
211178
func (u *Updater) fetchAndVerifyFullBin() ([]byte, error) {
212179
bin, err := u.fetchBin()
213180
if err != nil {
@@ -221,7 +188,7 @@ func (u *Updater) fetchAndVerifyFullBin() ([]byte, error) {
221188
}
222189

223190
func (u *Updater) fetchBin() ([]byte, error) {
224-
r, err := fetch(u.BinURL + u.CmdName + "/" + u.Info.Version + "/" + plat + ".gz")
191+
r, err := fetch(u.UpdateURL + u.CmdName + "/" + u.Info.Version + "/" + plat + ".gz")
225192
if err != nil {
226193
return nil, err
227194
}
@@ -258,7 +225,7 @@ func (u *Updater) update() error {
258225
}
259226
defer old.Close()
260227

261-
info, err := fetchInfo(u.APIURL, u.CmdName)
228+
info, err := fetchInfo(u.UpdateURL, u.CmdName)
262229
if err != nil {
263230
log.Println(err)
264231
return err
@@ -267,26 +234,15 @@ func (u *Updater) update() error {
267234
if u.Info.Version == u.CurrentVersion {
268235
return nil
269236
}
270-
bin, err := u.fetchAndVerifyPatch(old)
271-
if err != nil {
272-
switch err {
273-
case errHashMismatch:
274-
log.Println("update: hash mismatch from patched binary")
275-
case errDiffURLUndefined:
276-
log.Println("update: ", err)
277-
default:
278-
log.Println("update: patching binary, ", err)
279-
}
280237

281-
bin, err = u.fetchAndVerifyFullBin()
282-
if err != nil {
283-
if err == errHashMismatch {
284-
log.Println("update: hash mismatch from full binary")
285-
} else {
286-
log.Println("update: fetching full binary,", err)
287-
}
288-
return err
238+
bin, err := u.fetchAndVerifyFullBin()
239+
if err != nil {
240+
if err == errHashMismatch {
241+
log.Println("update: hash mismatch from full binary")
242+
} else {
243+
log.Println("update: fetching full binary,", err)
289244
}
245+
return err
290246
}
291247

292248
// close the old binary before installing because on windows

0 commit comments

Comments
 (0)