Skip to content

Commit 5d1ab01

Browse files
authored
Merge pull request containerd#8764 from AkihiroSuda/zero-whiteout-timestamp
2 parents a542a57 + 5dedb6d commit 5d1ab01

5 files changed

Lines changed: 22 additions & 19 deletions

File tree

api/services/diff/v1/diff.pb.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/services/diff/v1/diff.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ message DiffRequest {
7474
// on content store commit.
7575
map<string, string> labels = 5;
7676

77-
// SourceDateEpoch specifies the timestamp used for whiteouts to provide control for reproducibility.
77+
// SourceDateEpoch specifies the timestamp used to provide control for reproducibility.
7878
// See also https://reproducible-builds.org/docs/source-date-epoch/ .
79+
//
80+
// Since containerd v2.0, the whiteout timestamps are set to zero (1970-01-01),
81+
// not to the source date epoch.
7982
google.protobuf.Timestamp source_date_epoch = 6;
8083
}
8184

archive/tar.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ func WriteDiff(ctx context.Context, w io.Writer, a, b string, opts ...WriteDiffO
103103
func 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.
534526
func 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

archive/tar_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ func TestSourceDateEpoch(t *testing.T) {
11761176

11771177
opts := []WriteDiffOpt{WithSourceDateEpoch(&sourceDateEpoch)}
11781178
validators := []tarEntryValidator{
1179-
composeValidators(whiteoutEntry("f1"), requireModTime(sourceDateEpoch)),
1179+
composeValidators(whiteoutEntry("f1"), requireModTime(time.Unix(0, 0).UTC())), // not sourceDateEpoch
11801180
composeValidators(fileEntry("f2", []byte("content2"), 0644), requireModTime(past)),
11811181
composeValidators(fileEntry("f3", []byte("content3"), 0644), requireModTime(sourceDateEpoch)),
11821182
}

diff/diff.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ func WithPayloads(payloads map[string]typeurl.Any) ApplyOpt {
125125
}
126126
}
127127

128-
// WithSourceDateEpoch specifies the timestamp used for whiteouts to provide control for reproducibility.
128+
// WithSourceDateEpoch specifies the timestamp used to provide control for reproducibility.
129129
// See also https://reproducible-builds.org/docs/source-date-epoch/ .
130+
//
131+
// Since containerd v2.0, the whiteout timestamps are set to zero (1970-01-01),
132+
// not to the source date epoch.
130133
func WithSourceDateEpoch(tm *time.Time) Opt {
131134
return func(c *Config) error {
132135
c.SourceDateEpoch = tm

0 commit comments

Comments
 (0)