@@ -28,7 +28,6 @@ import (
28
28
"path/filepath"
29
29
"strings"
30
30
31
- "github.com/kr/binarydist"
32
31
log "github.com/sirupsen/logrus"
33
32
"gopkg.in/inconshreveable/go-update.v0"
34
33
)
@@ -60,7 +59,6 @@ import (
60
59
//
61
60
62
61
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" )
64
62
var up = update .New ()
65
63
66
64
func start (src string ) string {
@@ -81,16 +79,14 @@ func start(src string) string {
81
79
return ""
82
80
}
83
81
84
- func checkForUpdates (currentVersion string , updateAPIURL , updateBinURL string , cmdName string ) (string , error ) {
82
+ func checkForUpdates (currentVersion string , updateURL string , cmdName string ) (string , error ) {
85
83
path , err := os .Executable ()
86
84
if err != nil {
87
85
return "" , err
88
86
}
89
87
var up = & Updater {
90
88
CurrentVersion : currentVersion ,
91
- APIURL : updateAPIURL ,
92
- BinURL : updateBinURL ,
93
- DiffURL : "" ,
89
+ UpdateURL : updateURL ,
94
90
Dir : "update/" ,
95
91
CmdName : cmdName ,
96
92
}
@@ -139,9 +135,7 @@ func removeTempSuffixFromPath(path string) string {
139
135
//
140
136
// updater := &selfupdate.Updater{
141
137
// 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/",
145
139
// Dir: "update/",
146
140
// CmdName: "myapp", // app name
147
141
// }
@@ -150,10 +144,8 @@ func removeTempSuffixFromPath(path string) string {
150
144
// }
151
145
type Updater struct {
152
146
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).
154
148
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.
157
149
Dir string // Directory to store selfupdate state.
158
150
Info * availableUpdateInfo // Information about the available update.
159
151
}
@@ -183,31 +175,6 @@ func verifySha(bin []byte, sha []byte) bool {
183
175
return bytes .Equal (h .Sum (nil ), sha )
184
176
}
185
177
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
-
211
178
func (u * Updater ) fetchAndVerifyFullBin () ([]byte , error ) {
212
179
bin , err := u .fetchBin ()
213
180
if err != nil {
@@ -221,7 +188,7 @@ func (u *Updater) fetchAndVerifyFullBin() ([]byte, error) {
221
188
}
222
189
223
190
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" )
225
192
if err != nil {
226
193
return nil , err
227
194
}
@@ -258,7 +225,7 @@ func (u *Updater) update() error {
258
225
}
259
226
defer old .Close ()
260
227
261
- info , err := fetchInfo (u .APIURL , u .CmdName )
228
+ info , err := fetchInfo (u .UpdateURL , u .CmdName )
262
229
if err != nil {
263
230
log .Println (err )
264
231
return err
@@ -267,26 +234,15 @@ func (u *Updater) update() error {
267
234
if u .Info .Version == u .CurrentVersion {
268
235
return nil
269
236
}
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
- }
280
237
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 )
289
244
}
245
+ return err
290
246
}
291
247
292
248
// close the old binary before installing because on windows
0 commit comments