File tree Expand file tree Collapse file tree 3 files changed +54
-6
lines changed Expand file tree Collapse file tree 3 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,9 @@ is shown below:
169
169
The checksum query parameter is never sent to the backend protocol
170
170
implementation. It is used at a higher level by go-getter itself.
171
171
172
+ If the destination file exists and the checksums match: download
173
+ will be skipped.
174
+
172
175
### Unarchiving
173
176
174
177
go-getter will automatically unarchive files into a file or directory
Original file line number Diff line number Diff line change @@ -248,15 +248,24 @@ func (c *Client) Get() error {
248
248
// If we're not downloading a directory, then just download the file
249
249
// and return.
250
250
if mode == ClientModeFile {
251
- err := g .GetFile (dst , u )
252
- if err != nil {
253
- return err
254
- }
255
-
251
+ getFile := true
256
252
if checksumHash != nil {
257
- if err := checksum (dst , checksumHash , checksumValue ); err != nil {
253
+ if err := checksum (dst , checksumHash , checksumValue ); err == nil {
254
+ // don't get the file if the checksum of dst is correct
255
+ getFile = false
256
+ }
257
+ }
258
+ if getFile {
259
+ err := g .GetFile (dst , u )
260
+ if err != nil {
258
261
return err
259
262
}
263
+
264
+ if checksumHash != nil {
265
+ if err := checksum (dst , checksumHash , checksumValue ); err != nil {
266
+ return err
267
+ }
268
+ }
260
269
}
261
270
262
271
if decompressor != nil {
Original file line number Diff line number Diff line change @@ -378,3 +378,39 @@ func TestGetFile_filename(t *testing.T) {
378
378
t .Fatalf ("err: %s" , err )
379
379
}
380
380
}
381
+
382
+ func TestGetFile_checksumSkip (t * testing.T ) {
383
+ dst := tempFile (t )
384
+ u := testModule ("basic-file/foo.txt" ) + "?checksum=md5:09f7e02f1290be211da707a266f153b3"
385
+
386
+ getter := & MockGetter {Proxy : new (FileGetter )}
387
+ client := & Client {
388
+ Src : u ,
389
+ Dst : dst ,
390
+ Dir : false ,
391
+ Getters : map [string ]Getter {
392
+ "file" : getter ,
393
+ },
394
+ }
395
+
396
+ // get the file
397
+ if err := client .Get (); err != nil {
398
+ t .Fatalf ("err: %s" , err )
399
+ }
400
+
401
+ if v := getter .GetFileURL .Query ().Get ("checksum" ); v != "" {
402
+ t .Fatalf ("bad: %s" , v )
403
+ }
404
+
405
+ // remove proxy file getter and reset GetFileCalled so that we can re-test.
406
+ getter .Proxy = nil
407
+ getter .GetFileCalled = false
408
+
409
+ if err := client .Get (); err != nil {
410
+ t .Fatalf ("err: %s" , err )
411
+ }
412
+
413
+ if getter .GetFileCalled {
414
+ t .Fatalf ("get should not have been called" )
415
+ }
416
+ }
You can’t perform that action at this time.
0 commit comments