@@ -103,9 +103,9 @@ func WriteDiff(ctx context.Context, w io.Writer, a, b string, opts ...WriteDiffO
103103func writeDiffNaive (ctx context.Context , w io.Writer , a , b string , o WriteDiffOptions ) error {
104104 var opts []ChangeWriterOpt
105105 if o .SourceDateEpoch != nil {
106- opts = append (opts ,
107- WithModTimeUpperBound ( * o . SourceDateEpoch ),
108- WithWhiteoutTime ( * o . SourceDateEpoch ))
106+ opts = append (opts , WithModTimeUpperBound ( * o . SourceDateEpoch ))
107+ // Since containerd v2.0, the whiteout timestamps are set to zero (1970-01-01 ),
108+ // not to the source date epoch
109109 }
110110 cw := NewChangeWriter (w , b , opts ... )
111111 err := fs .Changes (ctx , a , b , cw .HandleChange )
@@ -505,7 +505,6 @@ type ChangeWriter struct {
505505 tw * tar.Writer
506506 source string
507507 modTimeUpperBound * time.Time
508- whiteoutT time.Time
509508 inodeSrc map [uint64 ]string
510509 inodeRefs map [uint64 ][]string
511510 addedDirs map [string ]struct {}
@@ -521,21 +520,13 @@ func WithModTimeUpperBound(tm time.Time) ChangeWriterOpt {
521520 }
522521}
523522
524- // WithWhiteoutTime sets the whiteout timestamp.
525- func WithWhiteoutTime (tm time.Time ) ChangeWriterOpt {
526- return func (cw * ChangeWriter ) {
527- cw .whiteoutT = tm
528- }
529- }
530-
531523// NewChangeWriter returns ChangeWriter that writes tar stream of the source directory
532524// to the privided writer. Change information (add/modify/delete/unmodified) for each
533525// file needs to be passed through HandleChange method.
534526func NewChangeWriter (w io.Writer , source string , opts ... ChangeWriterOpt ) * ChangeWriter {
535527 cw := & ChangeWriter {
536528 tw : tar .NewWriter (w ),
537529 source : source ,
538- whiteoutT : time .Now (), // can be overridden with WithWhiteoutTime(time.Time) ChangeWriterOpt .
539530 inodeSrc : map [uint64 ]string {},
540531 inodeRefs : map [uint64 ][]string {},
541532 addedDirs : map [string ]struct {}{},
@@ -557,13 +548,16 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
557548 whiteOutDir := filepath .Dir (p )
558549 whiteOutBase := filepath .Base (p )
559550 whiteOut := filepath .Join (whiteOutDir , whiteoutPrefix + whiteOutBase )
551+ // Since containerd v2.0, the whiteout timestamps are set to zero (1970-01-01),
552+ // not to the source date epoch.
553+ whiteOutT := time .Unix (0 , 0 ).UTC ()
560554 hdr := & tar.Header {
561555 Typeflag : tar .TypeReg ,
562556 Name : whiteOut [1 :],
563557 Size : 0 ,
564- ModTime : cw . whiteoutT ,
565- AccessTime : cw . whiteoutT ,
566- ChangeTime : cw . whiteoutT ,
558+ ModTime : whiteOutT ,
559+ AccessTime : whiteOutT ,
560+ ChangeTime : whiteOutT ,
567561 }
568562 if err := cw .includeParents (hdr ); err != nil {
569563 return err
0 commit comments