source.go 718 B

12345678910111213141516171819202122232425262728293031323334
  1. package contentutil
  2. import (
  3. "net/url"
  4. "strings"
  5. "github.com/containerd/containerd/content"
  6. "github.com/containerd/containerd/reference"
  7. )
  8. func HasSource(info content.Info, refspec reference.Spec) (bool, error) {
  9. u, err := url.Parse("dummy://" + refspec.Locator)
  10. if err != nil {
  11. return false, err
  12. }
  13. if info.Labels == nil {
  14. return false, nil
  15. }
  16. source, target := u.Hostname(), strings.TrimPrefix(u.Path, "/")
  17. repoLabel, ok := info.Labels["containerd.io/distribution.source."+source]
  18. if !ok || repoLabel == "" {
  19. return false, nil
  20. }
  21. for _, repo := range strings.Split(repoLabel, ",") {
  22. // the target repo is not a candidate
  23. if repo == target {
  24. return true, nil
  25. }
  26. }
  27. return false, nil
  28. }