Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion image/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type config struct {

func findConfig(w walker, d *descriptor) (*config, error) {
var c config
cpath := filepath.Join("blobs", d.normalizeDigest())
cpath := filepath.Join("blobs", d.algo(), d.hash())

switch err := w.walk(func(path string, info os.FileInfo, r io.Reader) error {
if info.IsDir() || filepath.Clean(path) != cpath {
Expand Down
24 changes: 18 additions & 6 deletions image/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,20 @@ type descriptor struct {
Size int64 `json:"size"`
}

func (d *descriptor) normalizeDigest() string {
return strings.Replace(d.Digest, ":", "-", -1)
func (d *descriptor) algo() string {
pts := strings.SplitN(d.Digest, ":", 2)
if len(pts) != 2 {
return ""
}
return pts[0]
}

func (d *descriptor) hash() string {
pts := strings.SplitN(d.Digest, ":", 2)
if len(pts) != 2 {
return ""
}
return pts[1]
}

func findDescriptor(w walker, name string) (*descriptor, error) {
Expand Down Expand Up @@ -67,8 +79,8 @@ func (d *descriptor) validate(w walker) error {
return nil
}

digest, err := filepath.Rel("blobs", filepath.Clean(path))
if err != nil || d.normalizeDigest() != digest {
filename, err := filepath.Rel(filepath.Join("blobs", d.algo()), filepath.Clean(path))
if err != nil || d.hash() != filename {
return nil
}

Expand All @@ -78,11 +90,11 @@ func (d *descriptor) validate(w walker) error {
return errEOW
}); err {
case nil:
return fmt.Errorf("%s: not found", d.normalizeDigest())
return fmt.Errorf("%s: not found", d.Digest)
case errEOW:
return nil
default:
return errors.Wrapf(err, "%s: validation failed", d.normalizeDigest())
return errors.Wrapf(err, "%s: validation failed", d.Digest)
}
}

Expand Down
6 changes: 3 additions & 3 deletions image/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type manifest struct {

func findManifest(w walker, d *descriptor) (*manifest, error) {
var m manifest
mpath := filepath.Join("blobs", d.normalizeDigest())
mpath := filepath.Join("blobs", d.algo(), d.hash())

switch err := w.walk(func(path string, info os.FileInfo, r io.Reader) error {
if info.IsDir() || filepath.Clean(path) != mpath {
Expand Down Expand Up @@ -98,8 +98,8 @@ func (m *manifest) unpack(w walker, dest string) error {
return nil
}

dd, err := filepath.Rel("blobs", filepath.Clean(path))
if err != nil || d.normalizeDigest() != dd {
dd, err := filepath.Rel(filepath.Join("blobs", d.algo()), filepath.Clean(path))
if err != nil || d.hash() != dd {
return nil
}

Expand Down