@@ -294,10 +294,6 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
294294 // If there is a subdir component, then we download the root separately
295295 // into a temporary directory, then copy over the proper subdir.
296296 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- }
301297
302298 var opts []ClientOption
303299
@@ -333,17 +329,29 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
333329 opts = g .client .Options
334330 }
335331
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.
338335 //
339336 // This prevents all default getters from being allowed when only using the
340337 // HttpGetter directly. To enable protocol switching, a client "wrapper" must
341338 // be used.
342339 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+ }
347355 }
348356
349357 // 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 {
352360 // which could be setup, if configured, at the top of this function.
353361 opts = append (opts , WithContext (ctx ))
354362
363+ if subDir != "" {
364+ // We have a subdir, time to jump some hoops
365+ return g .getSubdir (ctx , dst , source , subDir , opts ... )
366+ }
367+
355368 // Note: this allows the protocol to be switched to another configured getters.
356369 return Get (dst , source , opts ... )
357370}
@@ -495,7 +508,7 @@ func (g *HttpGetter) GetFile(dst string, src *url.URL) error {
495508
496509// getSubdir downloads the source into the destination, but with
497510// 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 {
499512 // Create a temporary directory to store the full source. This has to be
500513 // a non-existent directory.
501514 td , tdcloser , err := safetemp .Dir ("" , "getter" )
@@ -504,10 +517,6 @@ func (g *HttpGetter) getSubdir(ctx context.Context, dst, source, subDir string)
504517 }
505518 defer tdcloser .Close ()
506519
507- var opts []ClientOption
508- if g .client != nil {
509- opts = g .client .Options
510- }
511520 // Download that into the given directory
512521 if err := Get (td , source , opts ... ); err != nil {
513522 return err
0 commit comments