Skip to content

Commit 7e51cae

Browse files
committed
add new error since DiffURL is not used (no patch bin) and optimize code
Currently we only use BinURL for autoupdate (full bin)
1 parent 80d2c15 commit 7e51cae

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

updater/updater.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ const (
5555
const devValidTime = 7 * 24 * time.Hour
5656

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

60-
// TempPath generates a temporary path for the executable
61+
// TempPath generates a temporary path for the executable (adding "-temp")
6162
func TempPath(path string) string {
6263
if filepath.Ext(path) == "exe" {
6364
path = strings.Replace(path, ".exe", "-temp.exe", -1)
@@ -141,6 +142,9 @@ func verifySha(bin []byte, sha []byte) bool {
141142
}
142143

143144
func (u *Updater) fetchAndApplyPatch(old io.Reader) ([]byte, error) {
145+
if u.DiffURL == "" {
146+
return nil, errDiffUrlUndefined
147+
}
144148
r, err := fetch(u.DiffURL + u.CmdName + "/" + u.CurrentVersion + "/" + u.Info.Version + "/" + plat)
145149
if err != nil {
146150
return nil, err
@@ -238,12 +242,13 @@ func (u *Updater) update() error {
238242
}
239243
bin, err := u.fetchAndVerifyPatch(old)
240244
if err != nil {
241-
if err == errHashMismatch {
245+
switch err {
246+
case errHashMismatch:
242247
log.Println("update: hash mismatch from patched binary")
243-
} else {
244-
if u.DiffURL != "" {
245-
log.Println("update: patching binary,", err)
246-
}
248+
case errDiffUrlUndefined:
249+
log.Println("update: ", err)
250+
default:
251+
log.Println("update: patching binary, ", err)
247252
}
248253

249254
bin, err = u.fetchAndVerifyFullBin()

0 commit comments

Comments
 (0)