@@ -90,13 +90,20 @@ func GetFSFromImage(root string, img v1.Image) error {
9090 logrus .Infof ("Not adding %s because it was added by a prior layer" , path )
9191 continue
9292 }
93-
94- if CheckWhitelist (path ) && ! checkWhitelistRoot (root ) {
93+ whitelisted , err := CheckWhitelist (path )
94+ if err != nil {
95+ return err
96+ }
97+ if whitelisted && ! checkWhitelistRoot (root ) {
9598 logrus .Infof ("Not adding %s because it is whitelisted" , path )
9699 continue
97100 }
98101 if hdr .Typeflag == tar .TypeSymlink {
99- if CheckWhitelist (hdr .Linkname ) {
102+ whitelisted , err := CheckWhitelist (hdr .Linkname )
103+ if err != nil {
104+ return err
105+ }
106+ if whitelisted {
100107 logrus .Debugf ("skipping symlink from %s to %s because %s is whitelisted" , hdr .Linkname , path , hdr .Linkname )
101108 continue
102109 }
@@ -115,7 +122,11 @@ func GetFSFromImage(root string, img v1.Image) error {
115122func DeleteFilesystem () error {
116123 logrus .Info ("Deleting filesystem..." )
117124 err := filepath .Walk (constants .RootDir , func (path string , info os.FileInfo , err error ) error {
118- if CheckWhitelist (path ) || ChildDirInWhitelist (path , constants .RootDir ) {
125+ whitelisted , err := CheckWhitelist (path )
126+ if err != nil {
127+ return err
128+ }
129+ if whitelisted || ChildDirInWhitelist (path , constants .RootDir ) {
119130 logrus .Debugf ("Not deleting %s, as it's whitelisted" , path )
120131 return nil
121132 }
@@ -247,13 +258,18 @@ func checkWhiteouts(path string, whiteouts map[string]struct{}) bool {
247258 return false
248259}
249260
250- func CheckWhitelist (path string ) bool {
261+ func CheckWhitelist (path string ) (bool , error ) {
262+ abs , err := filepath .Abs (path )
263+ if err != nil {
264+ logrus .Infof ("unable to get absolute path for %s" , path )
265+ return false , err
266+ }
251267 for _ , wl := range whitelist {
252- if HasFilepathPrefix (path , wl ) {
253- return true
268+ if HasFilepathPrefix (abs , wl ) {
269+ return true , nil
254270 }
255271 }
256- return false
272+ return false , nil
257273}
258274
259275func checkWhitelistRoot (root string ) bool {
@@ -313,7 +329,11 @@ func RelativeFiles(fp string, root string) ([]string, error) {
313329 fullPath := filepath .Join (root , fp )
314330 logrus .Debugf ("Getting files and contents at root %s" , fullPath )
315331 err := filepath .Walk (fullPath , func (path string , info os.FileInfo , err error ) error {
316- if CheckWhitelist (path ) && ! HasFilepathPrefix (path , root ) {
332+ whitelisted , err := CheckWhitelist (path )
333+ if err != nil {
334+ return err
335+ }
336+ if whitelisted && ! HasFilepathPrefix (path , root ) {
317337 return nil
318338 }
319339 if err != nil {
@@ -334,7 +354,11 @@ func Files(root string) ([]string, error) {
334354 var files []string
335355 logrus .Debugf ("Getting files and contents at root %s" , root )
336356 err := filepath .Walk (root , func (path string , info os.FileInfo , err error ) error {
337- if CheckWhitelist (path ) {
357+ whitelisted , err := CheckWhitelist (path )
358+ if err != nil {
359+ return err
360+ }
361+ if whitelisted {
338362 return nil
339363 }
340364 files = append (files , path )
0 commit comments