@@ -45,7 +45,7 @@ type Config struct {
4545// Release is the interface to use the oc command to the get image info
4646type Release interface {
4747 GetBaseIso (architecture string ) (string , error )
48- ExtractFile (image string , filename string ) (string , error )
48+ ExtractFile (image string , filename string ) ([] string , error )
4949}
5050
5151type release struct {
@@ -75,20 +75,20 @@ const (
7575)
7676
7777// ExtractFile extracts the specified file from the given image name, and store it in the cache dir.
78- func (r * release ) ExtractFile (image string , filename string ) (string , error ) {
78+ func (r * release ) ExtractFile (image string , filename string ) ([] string , error ) {
7979 imagePullSpec , err := r .getImageFromRelease (image )
8080 if err != nil {
81- return "" , err
81+ return nil , err
8282 }
8383
8484 cacheDir , err := GetCacheDir (filesDataType )
8585 if err != nil {
86- return "" , err
86+ return nil , err
8787 }
8888
8989 path , err := r .extractFileFromImage (imagePullSpec , filename , cacheDir )
9090 if err != nil {
91- return "" , err
91+ return nil , err
9292 }
9393 return path , err
9494}
@@ -130,7 +130,7 @@ func (r *release) GetBaseIso(architecture string) (string, error) {
130130 return "" , err
131131 }
132132 logrus .Infof ("Base ISO obtained from release and cached at %s" , path )
133- return path , err
133+ return path [ 0 ] , err
134134}
135135
136136func (r * release ) getImageFromRelease (imageName string ) (string , error ) {
@@ -170,12 +170,12 @@ func (r *release) getImageFromRelease(imageName string) (string, error) {
170170 return image , nil
171171}
172172
173- func (r * release ) extractFileFromImage (image , file , cacheDir string ) (string , error ) {
173+ func (r * release ) extractFileFromImage (image , file , cacheDir string ) ([] string , error ) {
174174 var cmd string
175175 if len (r .mirrorConfig ) > 0 {
176176 icspFile , err := getIcspFileFromRegistriesConfig (r .mirrorConfig )
177177 if err != nil {
178- return "" , err
178+ return nil , err
179179 }
180180 defer removeIcspFile (icspFile )
181181 cmd = fmt .Sprintf (templateImageExtractWithIcsp , file , cacheDir , icspFile , image )
@@ -185,29 +185,25 @@ func (r *release) extractFileFromImage(image, file, cacheDir string) (string, er
185185 path := filepath .Join (cacheDir , path .Base (file ))
186186 // Remove file if it exists
187187 if err := removeCacheFile (path ); err != nil {
188- return "" , err
188+ return nil , err
189189 }
190190
191191 logrus .Debugf ("extracting %s to %s, %s" , file , cacheDir , cmd )
192192 _ , err := retry .Do (r .config .MaxTries , r .config .RetryDelay , execute , r .executer , r .pullSecret , cmd )
193193 if err != nil {
194- return "" , err
195- }
196- // Get actual file if the file ends in wildcard
197- if strings .HasSuffix (file , "*" ) {
198- path , err = getExtractedFileFromWildcard (path )
199- if err != nil {
200- return "" , err
201- }
194+ return nil , err
202195 }
203196
204- // Make sure file exists after extraction
205- if _ , err := os .Stat (path ); err != nil {
206- logrus .Debugf ("File %s was not found, err %s" , file , err .Error ())
207- return "" , err
197+ // Make sure file(s) exist after extraction
198+ matches , err := filepath .Glob (path )
199+ if err != nil {
200+ return nil , err
201+ }
202+ if matches == nil {
203+ return nil , fmt .Errorf ("file %s was not found" , file )
208204 }
209205
210- return path , nil
206+ return matches , nil
211207}
212208
213209// Get hash from rhcos.json
@@ -280,7 +276,7 @@ func (r *release) verifyCacheFile(image, file, architecture string) (bool, error
280276 return false , nil
281277 }
282278
283- payloadSha , err := os .ReadFile (shaFile )
279+ payloadSha , err := os .ReadFile (shaFile [ 0 ] )
284280 if err != nil {
285281 return false , err
286282 }
@@ -309,31 +305,6 @@ func removeCacheFile(path string) error {
309305 return nil
310306}
311307
312- func getExtractedFileFromWildcard (path string ) (string , error ) {
313- matches , err := filepath .Glob (path )
314- if err != nil {
315- return "" , err
316- }
317-
318- var found string
319- for _ , file := range matches {
320- fileInfo , err := os .Lstat (file )
321- if err != nil {
322- return "" , err
323- }
324- if fileInfo .Mode ()& os .ModeSymlink == 0 {
325- if found != "" {
326- logrus .Warningf ("Additional file %s matching %s in release" , filepath .Base (path ), filepath .Base (path ))
327- }
328- found = file
329- }
330- }
331- if found == "" {
332- return "" , fmt .Errorf ("failed to extract file %s" , filepath .Base (path ))
333- }
334- return found , nil
335- }
336-
337308func execute (executer executer.Executer , pullSecret , command string ) (string , error ) {
338309 ps , err := executer .TempFile ("" , "registry-config" )
339310 if err != nil {
0 commit comments