Skip to content

Commit

Permalink
Don't export whiteouts for single layers (#1629)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr committed Apr 6, 2023
1 parent d958444 commit 93be9c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/crane/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ func Export(img v1.Image, w io.Writer) error {
return err
}
if len(layers) == 1 {
// If it's a single layer, we don't have to flatten the filesystem.
// An added perk of skipping mutate.Extract here is that this works
// for non-tarball layers.
// If it's a single layer...
l := layers[0]
rc, err := l.Uncompressed()
mt, err := l.MediaType()
if err != nil {
return err
}
_, err = io.Copy(w, rc)
return err

if !mt.IsLayer() {
// ...and isn't an OCI mediaType, we don't have to flatten it.
// This lets export work for single layer, non-tarball images.
rc, err := l.Uncompressed()
if err != nil {
return err
}
_, err = io.Copy(w, rc)
return err
}
}
fs := mutate.Extract(img)
_, err = io.Copy(w, fs)
Expand Down
8 changes: 8 additions & 0 deletions pkg/v1/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ func (m MediaType) IsSchema1() bool {
}
return false
}

func (m MediaType) IsLayer() bool {
switch m {
case DockerLayer, DockerUncompressedLayer, OCILayer, OCILayerZStd, OCIUncompressedLayer, DockerForeignLayer, OCIRestrictedLayer, OCIUncompressedRestrictedLayer:
return true
}
return false
}

0 comments on commit 93be9c4

Please sign in to comment.