github.com/getong/docker@v1.13.1/distribution/pull_v2_windows.go (about)

     1  // +build windows
     2  
     3  package distribution
     4  
     5  import (
     6  	"net/http"
     7  	"os"
     8  
     9  	"github.com/Sirupsen/logrus"
    10  	"github.com/docker/distribution"
    11  	"github.com/docker/distribution/context"
    12  	"github.com/docker/distribution/manifest/schema2"
    13  	"github.com/docker/distribution/registry/client/transport"
    14  )
    15  
    16  var _ distribution.Describable = &v2LayerDescriptor{}
    17  
    18  func (ld *v2LayerDescriptor) Descriptor() distribution.Descriptor {
    19  	if ld.src.MediaType == schema2.MediaTypeForeignLayer && len(ld.src.URLs) > 0 {
    20  		return ld.src
    21  	}
    22  	return distribution.Descriptor{}
    23  }
    24  
    25  func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
    26  	if len(ld.src.URLs) == 0 {
    27  		blobs := ld.repo.Blobs(ctx)
    28  		return blobs.Open(ctx, ld.digest)
    29  	}
    30  
    31  	var (
    32  		err error
    33  		rsc distribution.ReadSeekCloser
    34  	)
    35  
    36  	// Find the first URL that results in a 200 result code.
    37  	for _, url := range ld.src.URLs {
    38  		logrus.Debugf("Pulling %v from foreign URL %v", ld.digest, url)
    39  		rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil)
    40  		_, err = rsc.Seek(0, os.SEEK_SET)
    41  		if err == nil {
    42  			break
    43  		}
    44  		logrus.Debugf("Download for %v failed: %v", ld.digest, err)
    45  		rsc.Close()
    46  		rsc = nil
    47  	}
    48  	return rsc, err
    49  }