diff --git a/pkg/executor/build.go b/pkg/executor/build.go index d9d00cbb0..38080b364 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -372,7 +372,8 @@ func (s *stageBuilder) build() error { files = command.FilesToSnapshot() timing.DefaultRun.Stop(t) - if !s.shouldTakeSnapshot(index, files, command.ProvidesFilesToSnapshot()) { + if !s.shouldTakeSnapshot(index, files, command.ProvidesFilesToSnapshot(), + command.ShouldDetectDeletedFiles()) { continue } if isCacheCommand { @@ -432,7 +433,7 @@ func (s *stageBuilder) takeSnapshot(files []string, shdDelete bool) (string, err return snapshot, err } -func (s *stageBuilder) shouldTakeSnapshot(index int, files []string, provideFiles bool) bool { +func (s *stageBuilder) shouldTakeSnapshot(index int, files []string, provideFiles bool, detectDeletion bool) bool { isLastCommand := index == len(s.cmds)-1 // We only snapshot the very end with single snapshot mode on. @@ -450,6 +451,9 @@ func (s *stageBuilder) shouldTakeSnapshot(index int, files []string, provideFile return true } + if detectDeletion { + return true + } // Don't snapshot an empty list. if len(files) == 0 { return false diff --git a/pkg/executor/build_test.go b/pkg/executor/build_test.go index 5182322a1..2dd0529d6 100644 --- a/pkg/executor/build_test.go +++ b/pkg/executor/build_test.go @@ -204,7 +204,7 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { opts: tt.fields.opts, cmds: tt.fields.cmds, } - if got := s.shouldTakeSnapshot(tt.args.index, tt.args.files, tt.args.hasFiles); got != tt.want { + if got := s.shouldTakeSnapshot(tt.args.index, tt.args.files, tt.args.hasFiles, false); got != tt.want { t.Errorf("stageBuilder.shouldTakeSnapshot() = %v, want %v", got, tt.want) } }) diff --git a/pkg/executor/fakes.go b/pkg/executor/fakes.go index cc85fb17f..193396f31 100644 --- a/pkg/executor/fakes.go +++ b/pkg/executor/fakes.go @@ -38,7 +38,7 @@ func (f fakeSnapShotter) Init() error { return nil } func (f fakeSnapShotter) TakeSnapshotFS() (string, error) { return f.tarPath, nil } -func (f fakeSnapShotter) TakeSnapshot(_ []string) (string, error) { +func (f fakeSnapShotter) TakeSnapshot(_ []string, _ bool) (string, error) { return f.tarPath, nil }