@@ -21,6 +21,7 @@ import (
2121 "log"
2222 "os"
2323 "path/filepath"
24+ "strings"
2425
2526 "github.com/opencontainers/image-spec/specs-go/v1"
2627 "github.com/pkg/errors"
@@ -140,12 +141,12 @@ func validate(w walker, refs []string, out *log.Logger) error {
140141// UnpackLayout walks through the file tree given by src and, using the layers
141142// specified in the manifest pointed to by the given ref, unpacks all layers in
142143// the given destination directory or returns an error if the unpacking failed.
143- func UnpackLayout (src , dest , ref string , platform [] string ) error {
144+ func UnpackLayout (src , dest , ref string , platform string ) error {
144145 return unpack (newPathWalker (src ), dest , ref , platform )
145146}
146147
147148// UnpackFile opens the file pointed by tarFileName and calls Unpack on it.
148- func UnpackFile (tarFileName , dest , ref string , platform [] string ) error {
149+ func UnpackFile (tarFileName , dest , ref string , platform string ) error {
149150 f , err := os .Open (tarFileName )
150151 if err != nil {
151152 return errors .Wrap (err , "unable to open file" )
@@ -159,11 +160,11 @@ func UnpackFile(tarFileName, dest, ref string, platform []string) error {
159160// the manifest pointed to by the given ref, unpacks all layers in the given
160161// destination directory or returns an error if the unpacking failed.
161162// The destination will be created if it does not exist.
162- func Unpack (r io.ReadSeeker , dest , refName string , platform [] string ) error {
163+ func Unpack (r io.ReadSeeker , dest , refName string , platform string ) error {
163164 return unpack (newTarWalker (r ), dest , refName , platform )
164165}
165166
166- func unpack (w walker , dest , refName string , platform [] string ) error {
167+ func unpack (w walker , dest , refName string , platform string ) error {
167168 if err := layoutValidate (w ); err != nil {
168169 return err
169170 }
@@ -216,13 +217,13 @@ func unpack(w walker, dest, refName string, platform []string) error {
216217// CreateRuntimeBundleLayout walks through the file tree given by src and
217218// creates an OCI runtime bundle in the given destination dest
218219// or returns an error if the unpacking failed.
219- func CreateRuntimeBundleLayout (src , dest , ref , root string , platform [] string ) error {
220+ func CreateRuntimeBundleLayout (src , dest , ref , root string , platform string ) error {
220221 return createRuntimeBundle (newPathWalker (src ), dest , ref , root , platform )
221222}
222223
223224// CreateRuntimeBundleFile opens the file pointed by tarFile and calls
224225// CreateRuntimeBundle.
225- func CreateRuntimeBundleFile (tarFile , dest , ref , root string , platform [] string ) error {
226+ func CreateRuntimeBundleFile (tarFile , dest , ref , root string , platform string ) error {
226227 f , err := os .Open (tarFile )
227228 if err != nil {
228229 return errors .Wrap (err , "unable to open file" )
@@ -235,11 +236,11 @@ func CreateRuntimeBundleFile(tarFile, dest, ref, root string, platform []string)
235236// CreateRuntimeBundle walks through the given tar stream and
236237// creates an OCI runtime bundle in the given destination dest
237238// or returns an error if the unpacking failed.
238- func CreateRuntimeBundle (r io.ReadSeeker , dest , ref , root string , platform [] string ) error {
239+ func CreateRuntimeBundle (r io.ReadSeeker , dest , ref , root string , platform string ) error {
239240 return createRuntimeBundle (newTarWalker (r ), dest , ref , root , platform )
240241}
241242
242- func createRuntimeBundle (w walker , dest , refName , rootfs string , platform [] string ) error {
243+ func createRuntimeBundle (w walker , dest , refName , rootfs string , platform string ) error {
243244 if err := layoutValidate (w ); err != nil {
244245 return err
245246 }
@@ -324,18 +325,19 @@ func createBundle(w walker, m *manifest, dest, rootfs string) error {
324325}
325326
326327// filertManifest returns a filtered list of manifests
327- func filterManifest (w walker , Manifests []v1.Descriptor , platform [] string ) ([]* manifest , error ) {
328+ func filterManifest (w walker , Manifests []v1.Descriptor , platform string ) ([]* manifest , error ) {
328329 var manifests []* manifest
329330
331+ argsParts := strings .Split (platform , ":" )
332+ if len (argsParts ) != 2 {
333+ return manifests , fmt .Errorf ("platform must have os and arch when reftype is index" )
334+ }
335+
330336 if len (Manifests ) == 0 {
331337 fmt .Println ("warning: no manifests found" )
332338 return manifests , nil
333339 }
334340
335- if len (platform ) != 2 {
336- return manifests , fmt .Errorf ("platform must have os and arch" )
337- }
338-
339341 for _ , manifest := range Manifests {
340342 m , err := findManifest (w , & manifest )
341343 if err != nil {
@@ -345,7 +347,7 @@ func filterManifest(w walker, Manifests []v1.Descriptor, platform []string) ([]*
345347 if err := m .validate (w ); err != nil {
346348 return manifests , err
347349 }
348- if manifest .Platform .OS == platform [0 ] && manifest .Platform .Architecture == platform [1 ] {
350+ if strings . EqualFold ( manifest .Platform .OS , argsParts [0 ]) && strings . EqualFold ( manifest .Platform .Architecture , argsParts [1 ]) {
349351 manifests = append (manifests , m )
350352 }
351353 }
0 commit comments