@@ -294,10 +294,6 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
294
294
// If there is a subdir component, then we download the root separately
295
295
// into a temporary directory, then copy over the proper subdir.
296
296
source , subDir := SourceDirSubdir (source )
297
- if subDir != "" {
298
- // We have a subdir, time to jump some hoops
299
- return g .getSubdir (ctx , dst , source , subDir )
300
- }
301
297
302
298
var opts []ClientOption
303
299
@@ -333,17 +329,29 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
333
329
opts = g .client .Options
334
330
}
335
331
336
- // If the client is nil, we know we're using the HttpGetter directly. In this case,
337
- // we don't know exactly which protocols are configued, but we can make a good guess.
332
+ // If the client is nil, we know we're using the HttpGetter directly. In
333
+ // this case, we don't know exactly which protocols are configured, but we
334
+ // can make a good guess.
338
335
//
339
336
// This prevents all default getters from being allowed when only using the
340
337
// HttpGetter directly. To enable protocol switching, a client "wrapper" must
341
338
// be used.
342
339
if g .client == nil {
343
- opts = append (opts , WithGetters (map [string ]Getter {
344
- "http" : g ,
345
- "https" : g ,
346
- }))
340
+ switch {
341
+ case subDir != "" :
342
+ // If there's a subdirectory, we will also need a file getter to
343
+ // unpack it.
344
+ opts = append (opts , WithGetters (map [string ]Getter {
345
+ "file" : new (FileGetter ),
346
+ "http" : g ,
347
+ "https" : g ,
348
+ }))
349
+ default :
350
+ opts = append (opts , WithGetters (map [string ]Getter {
351
+ "http" : g ,
352
+ "https" : g ,
353
+ }))
354
+ }
347
355
}
348
356
349
357
// Ensure we pass along the context we constructed in this function.
@@ -352,6 +360,11 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
352
360
// which could be setup, if configured, at the top of this function.
353
361
opts = append (opts , WithContext (ctx ))
354
362
363
+ if subDir != "" {
364
+ // We have a subdir, time to jump some hoops
365
+ return g .getSubdir (ctx , dst , source , subDir , opts ... )
366
+ }
367
+
355
368
// Note: this allows the protocol to be switched to another configured getters.
356
369
return Get (dst , source , opts ... )
357
370
}
@@ -495,7 +508,7 @@ func (g *HttpGetter) GetFile(dst string, src *url.URL) error {
495
508
496
509
// getSubdir downloads the source into the destination, but with
497
510
// the proper subdir.
498
- func (g * HttpGetter ) getSubdir (ctx context.Context , dst , source , subDir string ) error {
511
+ func (g * HttpGetter ) getSubdir (ctx context.Context , dst , source , subDir string , opts ... ClientOption ) error {
499
512
// Create a temporary directory to store the full source. This has to be
500
513
// a non-existent directory.
501
514
td , tdcloser , err := safetemp .Dir ("" , "getter" )
@@ -504,10 +517,6 @@ func (g *HttpGetter) getSubdir(ctx context.Context, dst, source, subDir string)
504
517
}
505
518
defer tdcloser .Close ()
506
519
507
- var opts []ClientOption
508
- if g .client != nil {
509
- opts = g .client .Options
510
- }
511
520
// Download that into the given directory
512
521
if err := Get (td , source , opts ... ); err != nil {
513
522
return err
0 commit comments