Fix: Flatten layer function needs to return existing files in the layer correctly (#2057)

* fix: Remove hardcoded whiteout prefix

* fix: Flatten function should return all existing files without whiteouts

* np: Documentation
This commit is contained in:
Gabriel Nützi
2022-04-26 16:46:09 -04:00
committed by GitHub
parent 9df31b1bcb
commit 76a54a031d
2 changed files with 11 additions and 7 deletions
+9 -5
View File
@@ -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
+2 -2
View File
@@ -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{}