2018-02-05 16:05:59 -05:00
|
|
|
package metadata // import "github.com/docker/docker/distribution/metadata"
|
2015-11-18 17:18:44 -05:00
|
|
|
|
|
|
|
import (
|
2019-08-05 10:37:47 -04:00
|
|
|
v1 "github.com/docker/docker/image/v1"
|
2015-11-18 17:18:44 -05:00
|
|
|
"github.com/docker/docker/layer"
|
2016-12-12 18:05:53 -05:00
|
|
|
"github.com/pkg/errors"
|
2015-11-18 17:18:44 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// V1IDService maps v1 IDs to layers on disk.
|
|
|
|
type V1IDService struct {
|
|
|
|
store Store
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewV1IDService creates a new V1 ID mapping service.
|
|
|
|
func NewV1IDService(store Store) *V1IDService {
|
|
|
|
return &V1IDService{
|
|
|
|
store: store,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// namespace returns the namespace used by this service.
|
|
|
|
func (idserv *V1IDService) namespace() string {
|
|
|
|
return "v1id"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get finds a layer by its V1 ID.
|
2015-11-13 19:59:01 -05:00
|
|
|
func (idserv *V1IDService) Get(v1ID, registry string) (layer.DiffID, error) {
|
2016-12-12 18:05:53 -05:00
|
|
|
if idserv.store == nil {
|
|
|
|
return "", errors.New("no v1IDService storage")
|
|
|
|
}
|
2015-11-18 17:18:44 -05:00
|
|
|
if err := v1.ValidateID(v1ID); err != nil {
|
2015-11-13 19:59:01 -05:00
|
|
|
return layer.DiffID(""), err
|
2015-11-18 17:18:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
idBytes, err := idserv.store.Get(idserv.namespace(), registry+","+v1ID)
|
|
|
|
if err != nil {
|
2015-11-13 19:59:01 -05:00
|
|
|
return layer.DiffID(""), err
|
2015-11-18 17:18:44 -05:00
|
|
|
}
|
2015-11-13 19:59:01 -05:00
|
|
|
return layer.DiffID(idBytes), nil
|
2015-11-18 17:18:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set associates an image with a V1 ID.
|
2015-11-13 19:59:01 -05:00
|
|
|
func (idserv *V1IDService) Set(v1ID, registry string, id layer.DiffID) error {
|
2016-12-12 18:05:53 -05:00
|
|
|
if idserv.store == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2015-11-18 17:18:44 -05:00
|
|
|
if err := v1.ValidateID(v1ID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return idserv.store.Set(idserv.namespace(), registry+","+v1ID, []byte(id))
|
|
|
|
}
|