pull_v2_windows.go 1.4 KB

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