@@ -8,15 +8,13 @@ import (
88 "encoding/json"
99 "fmt"
1010 "io"
11- "io/fs"
1211 "os"
1312 "os/exec"
1413 "path"
1514 "path/filepath"
1615 "strings"
1716 "time"
1817
19- "github.com/pkg/errors"
2018 "github.com/sirupsen/logrus"
2119 "github.com/thedevsaddam/retry"
2220 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -184,10 +182,9 @@ func (r *release) extractFileFromImage(image, file, cacheDir string) (string, er
184182 } else {
185183 cmd = fmt .Sprintf (templateImageExtract , file , cacheDir , image )
186184 }
187- // Remove file if it exists
188185 path := filepath .Join (cacheDir , path .Base (file ))
189- if err := os . Remove ( path ); err != nil && ! errors . Is ( err , fs . ErrNotExist ) {
190- logrus . Debugf ( "Could not remove existing baseISO %s" , path )
186+ // Remove file if it exists
187+ if err := removeCacheFile ( path ); err != nil {
191188 return "" , err
192189 }
193190
@@ -196,6 +193,14 @@ func (r *release) extractFileFromImage(image, file, cacheDir string) (string, er
196193 if err != nil {
197194 return "" , err
198195 }
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+ }
202+ }
203+
199204 // Make sure file exists after extraction
200205 if _ , err := os .Stat (path ); err != nil {
201206 logrus .Debugf ("File %s was not found, err %s" , file , err .Error ())
@@ -288,6 +293,47 @@ func (r *release) verifyCacheFile(image, file, architecture string) (bool, error
288293 return false , nil
289294}
290295
296+ // Remove any existing files in the cache.
297+ func removeCacheFile (path string ) error {
298+ matches , err := filepath .Glob (path )
299+ if err != nil {
300+ return err
301+ }
302+
303+ for _ , file := range matches {
304+ if err = os .Remove (file ); err != nil {
305+ return err
306+ }
307+ logrus .Debugf ("Removed file %s" , file )
308+ }
309+ return nil
310+ }
311+
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+
291337func execute (executer executer.Executer , pullSecret , command string ) (string , error ) {
292338 ps , err := executer .TempFile ("" , "registry-config" )
293339 if err != nil {
0 commit comments