@@ -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"
@@ -136,12 +137,12 @@ func validate(w walker, refs []string, out *log.Logger) error {
136137// UnpackLayout walks through the file tree given by src and, using the layers
137138// specified in the manifest pointed to by the given ref, unpacks all layers in
138139// the given destination directory or returns an error if the unpacking failed.
139- func UnpackLayout (src , dest , ref string , platform [] string ) error {
140+ func UnpackLayout (src , dest , ref string , platform string ) error {
140141 return unpack (newPathWalker (src ), dest , ref , platform )
141142}
142143
143144// UnpackFile opens the file pointed by tarFileName and calls Unpack on it.
144- func UnpackFile (tarFileName , dest , ref string , platform [] string ) error {
145+ func UnpackFile (tarFileName , dest , ref string , platform string ) error {
145146 f , err := os .Open (tarFileName )
146147 if err != nil {
147148 return errors .Wrap (err , "unable to open file" )
@@ -155,11 +156,11 @@ func UnpackFile(tarFileName, dest, ref string, platform []string) error {
155156// the manifest pointed to by the given ref, unpacks all layers in the given
156157// destination directory or returns an error if the unpacking failed.
157158// The destination will be created if it does not exist.
158- func Unpack (r io.ReadSeeker , dest , refName string , platform [] string ) error {
159+ func Unpack (r io.ReadSeeker , dest , refName string , platform string ) error {
159160 return unpack (newTarWalker (r ), dest , refName , platform )
160161}
161162
162- func unpack (w walker , dest , refName string , platform [] string ) error {
163+ func unpack (w walker , dest , refName string , platform string ) error {
163164 ref , err := findDescriptor (w , refName )
164165 if err != nil {
165166 return err
@@ -208,13 +209,13 @@ func unpack(w walker, dest, refName string, platform []string) error {
208209// CreateRuntimeBundleLayout walks through the file tree given by src and
209210// creates an OCI runtime bundle in the given destination dest
210211// or returns an error if the unpacking failed.
211- func CreateRuntimeBundleLayout (src , dest , ref , root string , platform [] string ) error {
212+ func CreateRuntimeBundleLayout (src , dest , ref , root string , platform string ) error {
212213 return createRuntimeBundle (newPathWalker (src ), dest , ref , root , platform )
213214}
214215
215216// CreateRuntimeBundleFile opens the file pointed by tarFile and calls
216217// CreateRuntimeBundle.
217- func CreateRuntimeBundleFile (tarFile , dest , ref , root string , platform [] string ) error {
218+ func CreateRuntimeBundleFile (tarFile , dest , ref , root string , platform string ) error {
218219 f , err := os .Open (tarFile )
219220 if err != nil {
220221 return errors .Wrap (err , "unable to open file" )
@@ -227,11 +228,11 @@ func CreateRuntimeBundleFile(tarFile, dest, ref, root string, platform []string)
227228// CreateRuntimeBundle walks through the given tar stream and
228229// creates an OCI runtime bundle in the given destination dest
229230// or returns an error if the unpacking failed.
230- func CreateRuntimeBundle (r io.ReadSeeker , dest , ref , root string , platform [] string ) error {
231+ func CreateRuntimeBundle (r io.ReadSeeker , dest , ref , root string , platform string ) error {
231232 return createRuntimeBundle (newTarWalker (r ), dest , ref , root , platform )
232233}
233234
234- func createRuntimeBundle (w walker , dest , refName , rootfs string , platform [] string ) error {
235+ func createRuntimeBundle (w walker , dest , refName , rootfs string , platform string ) error {
235236 ref , err := findDescriptor (w , refName )
236237 if err != nil {
237238 return err
@@ -312,18 +313,19 @@ func createBundle(w walker, m *manifest, dest, rootfs string) error {
312313}
313314
314315// filertManifest returns a filtered list of manifests
315- func filterManifest (w walker , Manifests []v1.Descriptor , platform [] string ) ([]* manifest , error ) {
316+ func filterManifest (w walker , Manifests []v1.Descriptor , platform string ) ([]* manifest , error ) {
316317 var manifests []* manifest
317318
319+ argsParts := strings .Split (platform , ":" )
320+ if len (argsParts ) != 2 {
321+ return manifests , fmt .Errorf ("platform must have os and arch when reftype is index" )
322+ }
323+
318324 if len (Manifests ) == 0 {
319325 fmt .Println ("warning: no manifests found" )
320326 return manifests , nil
321327 }
322328
323- if len (platform ) != 2 {
324- return manifests , fmt .Errorf ("platform must have os and arch" )
325- }
326-
327329 for _ , manifest := range Manifests {
328330 m , err := findManifest (w , & manifest )
329331 if err != nil {
@@ -333,7 +335,7 @@ func filterManifest(w walker, Manifests []v1.Descriptor, platform []string) ([]*
333335 if err := m .validate (w ); err != nil {
334336 return manifests , err
335337 }
336- if manifest .Platform .OS == platform [0 ] && manifest .Platform .Architecture == platform [1 ] {
338+ if strings . EqualFold ( manifest .Platform .OS , argsParts [0 ]) && strings . EqualFold ( manifest .Platform .Architecture , argsParts [1 ]) {
337339 manifests = append (manifests , m )
338340 }
339341 }
0 commit comments