@@ -55,9 +55,10 @@ const (
5555const devValidTime = 7 * 24 * time .Hour
5656
5757var 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" )
5859var up = update .New ()
5960
60- // TempPath generates a temporary path for the executable
61+ // TempPath generates a temporary path for the executable (adding "-temp")
6162func 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
143144func (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