Clean up layer storage layout
Previously, discussions were still ongoing about different storage layouts that could support various access models. This changeset removes a layer of indirection that was in place due to earlier designs. Effectively, this both associates a layer with a named repository and ensures that content cannot be accessed across repositories. It also moves to rely on tarsum as a true content-addressable identifier, removing a layer of indirection during blob resolution.
This commit is contained in:
parent
756989c011
commit
68944ea9cf
6 changed files with 153 additions and 270 deletions
|
@ -47,32 +47,9 @@ var (
|
|||
// ParseDigest parses s and returns the validated digest object. An error will
|
||||
// be returned if the format is invalid.
|
||||
func ParseDigest(s string) (Digest, error) {
|
||||
// Common case will be tarsum
|
||||
_, err := common.ParseTarSum(s)
|
||||
if err == nil {
|
||||
return Digest(s), nil
|
||||
}
|
||||
d := Digest(s)
|
||||
|
||||
// Continue on for general parser
|
||||
|
||||
i := strings.Index(s, ":")
|
||||
if i < 0 {
|
||||
return "", ErrDigestInvalidFormat
|
||||
}
|
||||
|
||||
// case: "sha256:" with no hex.
|
||||
if i+1 == len(s) {
|
||||
return "", ErrDigestInvalidFormat
|
||||
}
|
||||
|
||||
switch s[:i] {
|
||||
case "md5", "sha1", "sha256":
|
||||
break
|
||||
default:
|
||||
return "", ErrDigestUnsupported
|
||||
}
|
||||
|
||||
return Digest(s), nil
|
||||
return d, d.Validate()
|
||||
}
|
||||
|
||||
// FromReader returns the most valid digest for the underlying content.
|
||||
|
@ -119,6 +96,38 @@ func FromBytes(p []byte) (Digest, error) {
|
|||
return FromReader(bytes.NewReader(p))
|
||||
}
|
||||
|
||||
// Validate checks that the contents of d is a valid digest, returning an
|
||||
// error if not.
|
||||
func (d Digest) Validate() error {
|
||||
s := string(d)
|
||||
// Common case will be tarsum
|
||||
_, err := common.ParseTarSum(s)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Continue on for general parser
|
||||
|
||||
i := strings.Index(s, ":")
|
||||
if i < 0 {
|
||||
return ErrDigestInvalidFormat
|
||||
}
|
||||
|
||||
// case: "sha256:" with no hex.
|
||||
if i+1 == len(s) {
|
||||
return ErrDigestInvalidFormat
|
||||
}
|
||||
|
||||
switch s[:i] {
|
||||
case "md5", "sha1", "sha256":
|
||||
break
|
||||
default:
|
||||
return ErrDigestUnsupported
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Algorithm returns the algorithm portion of the digest. This will panic if
|
||||
// the underlying digest is not in a valid format.
|
||||
func (d Digest) Algorithm() string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue