add deletion logic
This commit is contained in:
parent
2a7d33526b
commit
b7462742c1
|
|
@ -372,7 +372,8 @@ func (s *stageBuilder) build() error {
|
||||||
files = command.FilesToSnapshot()
|
files = command.FilesToSnapshot()
|
||||||
timing.DefaultRun.Stop(t)
|
timing.DefaultRun.Stop(t)
|
||||||
|
|
||||||
if !s.shouldTakeSnapshot(index, files, command.ProvidesFilesToSnapshot()) {
|
if !s.shouldTakeSnapshot(index, files, command.ProvidesFilesToSnapshot(),
|
||||||
|
command.ShouldDetectDeletedFiles()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if isCacheCommand {
|
if isCacheCommand {
|
||||||
|
|
@ -432,7 +433,7 @@ func (s *stageBuilder) takeSnapshot(files []string, shdDelete bool) (string, err
|
||||||
return snapshot, 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
|
isLastCommand := index == len(s.cmds)-1
|
||||||
|
|
||||||
// We only snapshot the very end with single snapshot mode on.
|
// 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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if detectDeletion {
|
||||||
|
return true
|
||||||
|
}
|
||||||
// Don't snapshot an empty list.
|
// Don't snapshot an empty list.
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
|
||||||
opts: tt.fields.opts,
|
opts: tt.fields.opts,
|
||||||
cmds: tt.fields.cmds,
|
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)
|
t.Errorf("stageBuilder.shouldTakeSnapshot() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func (f fakeSnapShotter) Init() error { return nil }
|
||||||
func (f fakeSnapShotter) TakeSnapshotFS() (string, error) {
|
func (f fakeSnapShotter) TakeSnapshotFS() (string, error) {
|
||||||
return f.tarPath, nil
|
return f.tarPath, nil
|
||||||
}
|
}
|
||||||
func (f fakeSnapShotter) TakeSnapshot(_ []string) (string, error) {
|
func (f fakeSnapShotter) TakeSnapshot(_ []string, _ bool) (string, error) {
|
||||||
return f.tarPath, nil
|
return f.tarPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue