// ParseStoreReference takes a name or an ID, tries to figure out which it is // relative to the given store, and returns it in a reference object. func (s storageTransport) ParseStoreReference(store storage.Store, ref string) (*storageReference, error) { var name reference.Named var sum digest.Digest var err error if ref == "" { return nil, ErrInvalidReference } if ref[0] == '[' { // Ignore the store specifier. closeIndex := strings.IndexRune(ref, ']') if closeIndex < 1 { return nil, ErrInvalidReference } ref = ref[closeIndex+1:] } refInfo := strings.SplitN(ref, "@", 2) if len(refInfo) == 1 { // A name. name, err = reference.ParseNamed(refInfo[0]) if err != nil { return nil, err } } else if len(refInfo) == 2 { // An ID, possibly preceded by a name. if refInfo[0] != "" { name, err = reference.ParseNamed(refInfo[0]) if err != nil { return nil, err } } sum, err = digest.Parse("sha256:" + refInfo[1]) if err != nil { return nil, err } } else { // Coverage: len(refInfo) is always 1 or 2 // Anything else: store specified in a form we don't // recognize. return nil, ErrInvalidReference } storeSpec := "[" + store.GetGraphDriverName() + "@" + store.GetGraphRoot() + "]" id := "" if sum.Validate() == nil { id = sum.Hex() } refname := "" if name != nil { name = reference.WithDefaultTag(name) refname = verboseName(name) } if refname == "" { logrus.Debugf("parsed reference into %q", storeSpec+"@"+id) } else if id == "" { logrus.Debugf("parsed reference into %q", storeSpec+refname) } else { logrus.Debugf("parsed reference into %q", storeSpec+refname+"@"+id) } return newReference(storageTransport{store: store}, refname, id, name), nil }
func (s storageTransport) GetStoreImage(store storage.Store, ref types.ImageReference) (*storage.Image, error) { dref := ref.DockerReference() if dref == nil { if sref, ok := ref.(*storageReference); ok { if sref.id != "" { if img, err := store.GetImage(sref.id); err == nil { return img, nil } } } return nil, ErrInvalidReference } return store.GetImage(verboseName(dref)) }
func diffLayer(store storage.Store, layerID string) (rc io.ReadCloser, n int64, err error) { layer, err := store.GetLayer(layerID) if err != nil { return nil, -1, err } layerMeta := storageLayerMetadata{ CompressedSize: -1, } if layer.Metadata != "" { if err := json.Unmarshal([]byte(layer.Metadata), &layerMeta); err != nil { return nil, -1, errors.Wrapf(err, "error decoding metadata for layer %q", layerID) } } if layerMeta.CompressedSize <= 0 { n = -1 } else { n = layerMeta.CompressedSize } diff, err := store.Diff("", layer.ID) if err != nil { return nil, -1, err } return diff, n, nil }