@@ -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
6261var 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" )
6462var up = update .New ()
6563
6664func 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// }
151145type 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-
211178func (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
223190func (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