pull_v2_windows.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. if len(ld.src.URLs) == 0 {
  21. blobs := ld.repo.Blobs(ctx)
  22. return blobs.Open(ctx, ld.digest)
  23. }
  24. var (
  25. err error
  26. rsc distribution.ReadSeekCloser
  27. )
  28. // Find the first URL that results in a 200 result code.
  29. for _, url := range ld.src.URLs {
  30. logrus.Debugf("Pulling %v from foreign URL %v", ld.digest, url)
  31. rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil)
  32. _, err = rsc.Seek(0, os.SEEK_SET)
  33. if err == nil {
  34. break
  35. }
  36. logrus.Debugf("Download for %v failed: %v", ld.digest, err)
  37. rsc.Close()
  38. rsc = nil
  39. }
  40. return rsc, err
  41. }