diff --git a/pkg/snapshot/layered_map.go b/pkg/snapshot/layered_map.go index 976ad19d1..60e802b7b 100644 --- a/pkg/snapshot/layered_map.go +++ b/pkg/snapshot/layered_map.go @@ -26,6 +26,7 @@ import ( "github.com/GoogleContainerTools/kaniko/pkg/timing" "github.com/GoogleContainerTools/kaniko/pkg/util" + "github.com/docker/docker/pkg/archive" "github.com/sirupsen/logrus" ) @@ -61,15 +62,18 @@ func (l *LayeredMap) Key() (string, error) { return util.SHA256(c) } -// GetFlattenedPathsForWhiteOut returns all paths in the current FS -func (l *LayeredMap) getFlattenedPathsForWhiteOut() map[string]struct{} { +// getFlattenedPaths returns all existing paths in the current FS +func (l *LayeredMap) getFlattenedPaths() map[string]struct{} { paths := map[string]struct{}{} for _, l := range l.layers { for p := range l { - if strings.HasPrefix(filepath.Base(p), ".wh.") { - delete(paths, p) + basename := filepath.Base(p) + if strings.HasPrefix(basename, archive.WhiteoutPrefix) { + deletedFile := filepath.Join(filepath.Dir(p), strings.TrimPrefix(basename, archive.WhiteoutPrefix)) + delete(paths, deletedFile) + } else { + paths[p] = struct{}{} } - paths[p] = struct{}{} } } return paths diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index ba7371846..50fa803a0 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -93,7 +93,7 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool, forceBui // Get whiteout paths filesToWhiteout := []string{} if shdCheckDelete { - _, deletedFiles := util.WalkFS(s.directory, s.l.getFlattenedPathsForWhiteOut(), func(s string) (bool, error) { + _, deletedFiles := util.WalkFS(s.directory, s.l.getFlattenedPaths(), func(s string) (bool, error) { return true, nil }) // The paths left here are the ones that have been deleted in this layer. @@ -159,7 +159,7 @@ func (s *Snapshotter) scanFullFilesystem() ([]string, []string, error) { s.l.Snapshot() - changedPaths, deletedPaths := util.WalkFS(s.directory, s.l.getFlattenedPathsForWhiteOut(), s.l.CheckFileChange) + changedPaths, deletedPaths := util.WalkFS(s.directory, s.l.getFlattenedPaths(), s.l.CheckFileChange) timer := timing.Start("Resolving Paths") filesToAdd := []string{}