@@ -55,9 +55,10 @@ const (
55
55
const devValidTime = 7 * 24 * time .Hour
56
56
57
57
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" )
58
59
var up = update .New ()
59
60
60
- // TempPath generates a temporary path for the executable
61
+ // TempPath generates a temporary path for the executable (adding "-temp")
61
62
func TempPath (path string ) string {
62
63
if filepath .Ext (path ) == "exe" {
63
64
path = strings .Replace (path , ".exe" , "-temp.exe" , - 1 )
@@ -141,6 +142,9 @@ func verifySha(bin []byte, sha []byte) bool {
141
142
}
142
143
143
144
func (u * Updater ) fetchAndApplyPatch (old io.Reader ) ([]byte , error ) {
145
+ if u .DiffURL == "" {
146
+ return nil , errDiffUrlUndefined
147
+ }
144
148
r , err := fetch (u .DiffURL + u .CmdName + "/" + u .CurrentVersion + "/" + u .Info .Version + "/" + plat )
145
149
if err != nil {
146
150
return nil , err
@@ -238,12 +242,13 @@ func (u *Updater) update() error {
238
242
}
239
243
bin , err := u .fetchAndVerifyPatch (old )
240
244
if err != nil {
241
- if err == errHashMismatch {
245
+ switch err {
246
+ case errHashMismatch :
242
247
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 )
247
252
}
248
253
249
254
bin , err = u .fetchAndVerifyFullBin ()
0 commit comments