mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-19 00:23:22 +02:00
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:
@@ -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
|
||||
|
||||
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user