Tizen_4.0 base
[platform/upstream/docker-engine.git] / distribution / pull_v2_windows.go
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         blobs := ld.repo.Blobs(ctx)
27         rsc, err := blobs.Open(ctx, ld.digest)
28
29         if len(ld.src.URLs) == 0 {
30                 return rsc, err
31         }
32
33         // We're done if the registry has this blob.
34         if err == nil {
35                 // Seek does an HTTP GET.  If it succeeds, the blob really is accessible.
36                 if _, err = rsc.Seek(0, os.SEEK_SET); err == nil {
37                         return rsc, nil
38                 }
39                 rsc.Close()
40         }
41
42         // Find the first URL that results in a 200 result code.
43         for _, url := range ld.src.URLs {
44                 logrus.Debugf("Pulling %v from foreign URL %v", ld.digest, url)
45                 rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil)
46
47                 // Seek does an HTTP GET.  If it succeeds, the blob really is accessible.
48                 _, err = rsc.Seek(0, os.SEEK_SET)
49                 if err == nil {
50                         break
51                 }
52                 logrus.Debugf("Download for %v failed: %v", ld.digest, err)
53                 rsc.Close()
54                 rsc = nil
55         }
56         return rsc, err
57 }