better shdTakeSnapshot
This commit is contained in:
		
							parent
							
								
									b7462742c1
								
							
						
					
					
						commit
						c85d64c8ae
					
				|  | @ -52,6 +52,6 @@ func (b *BaseCommand) ShouldCacheOutput() bool { | ||||||
| 	return false | 	return false | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (a *BaseCommand) ShouldDetectDeletedFiles() bool { | func (b *BaseCommand) ShouldDetectDeletedFiles() bool { | ||||||
| 	return false | 	return false | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -372,8 +372,7 @@ 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.MetadataOnly()) { | ||||||
| 			command.ShouldDetectDeletedFiles()) { |  | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		if isCacheCommand { | 		if isCacheCommand { | ||||||
|  | @ -433,7 +432,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, detectDeletion bool) bool { | func (s *stageBuilder) shouldTakeSnapshot(index int, files []string, isMetadatCmd 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.
 | ||||||
|  | @ -446,20 +445,8 @@ func (s *stageBuilder) shouldTakeSnapshot(index int, files []string, provideFile | ||||||
| 		return true | 		return true | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// if command does not provide files, snapshot everything.
 | 	// if command is a metadata command, do not snapshot.
 | ||||||
| 	if !provideFiles { | 	return !isMetadatCmd | ||||||
| 		return true |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if detectDeletion { |  | ||||||
| 		return true |  | ||||||
| 	} |  | ||||||
| 	// Don't snapshot an empty list.
 |  | ||||||
| 	if len(files) == 0 { |  | ||||||
| 		return false |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return true |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *stageBuilder) saveSnapshotToImage(createdBy string, tarPath string) error { | func (s *stageBuilder) saveSnapshotToImage(createdBy string, tarPath string) error { | ||||||
|  |  | ||||||
|  | @ -105,7 +105,7 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { | ||||||
| 	type args struct { | 	type args struct { | ||||||
| 		index        int | 		index        int | ||||||
| 		files        []string | 		files        []string | ||||||
| 		hasFiles bool | 		metadataOnly bool | ||||||
| 	} | 	} | ||||||
| 	tests := []struct { | 	tests := []struct { | ||||||
| 		name   string | 		name   string | ||||||
|  | @ -160,7 +160,7 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { | ||||||
| 			args: args{ | 			args: args{ | ||||||
| 				index:        0, | 				index:        0, | ||||||
| 				files:        []string{}, | 				files:        []string{}, | ||||||
| 				hasFiles: true, | 				metadataOnly: true, | ||||||
| 			}, | 			}, | ||||||
| 			want: false, | 			want: false, | ||||||
| 		}, | 		}, | ||||||
|  | @ -174,7 +174,7 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { | ||||||
| 			args: args{ | 			args: args{ | ||||||
| 				index:        0, | 				index:        0, | ||||||
| 				files:        nil, | 				files:        nil, | ||||||
| 				hasFiles: false, | 				metadataOnly: false, | ||||||
| 			}, | 			}, | ||||||
| 			want: true, | 			want: true, | ||||||
| 		}, | 		}, | ||||||
|  | @ -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, false); got != tt.want { | 			if got := s.shouldTakeSnapshot(tt.args.index, tt.args.files, !tt.args.metadataOnly); got != tt.want { | ||||||
| 				t.Errorf("stageBuilder.shouldTakeSnapshot() = %v, want %v", got, tt.want) | 				t.Errorf("stageBuilder.shouldTakeSnapshot() = %v, want %v", got, tt.want) | ||||||
| 			} | 			} | ||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
|  | @ -111,7 +111,6 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool) (string, | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	logrus.Infof("whiteouts %s", filesToWhiteout) |  | ||||||
| 	t := util.NewTar(f) | 	t := util.NewTar(f) | ||||||
| 	defer t.Close() | 	defer t.Close() | ||||||
| 	if err := writeToTar(t, filesToAdd, filesToWhiteout); err != nil { | 	if err := writeToTar(t, filesToAdd, filesToWhiteout); err != nil { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue