Skip to content

Commit bd7a3b1

Browse files
committed
only ignore timestamps in PAXRecords
Signed-off-by: Martin Zihlmann <[email protected]>
1 parent 192c8ad commit bd7a3b1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/diff/diff.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,10 +865,17 @@ func (d *differ) diffTarEntries(ctx context.Context, node *EventTreeNode, in [2]
865865

866866
func (d *differ) diffTarEntry(ctx context.Context, node *EventTreeNode, in [2]EventInput) (dirsToBeRemovedIfEmpty []string, retErr error) {
867867
var negligibleTarFields []string
868+
var negligiblePAXFields map[string]struct{}
868869
if d.o.IgnoreTimestamps {
869870
negligibleTarFields = append(negligibleTarFields, "ModTime", "AccessTime", "ChangeTime", "PAXRecords")
871+
negligiblePAXFields = map[string]struct{}{"mtime": {}, "atime": {}, "ctime": {}}
872+
}
873+
discardFunc := func(k, _ string) bool {
874+
_, ok := negligiblePAXFields[k]
875+
return ok
870876
}
871877
cmpOpts := []cmp.Option{cmpopts.IgnoreUnexported(TarEntry{}), cmpopts.IgnoreFields(tar.Header{}, negligibleTarFields...)}
878+
paxOpts := []cmp.Option{cmpopts.IgnoreMapEntries(discardFunc)}
872879
ent0, ent1 := *in[0].TarEntry, *in[1].TarEntry
873880
if d.o.IgnoreFileOrder {
874881
// cmpopts.IgnoreFields cannot be used for int
@@ -892,6 +899,16 @@ func (d *differ) diffTarEntry(ctx context.Context, node *EventTreeNode, in [2]Ev
892899
if err := d.raiseEvent(ctx, node, ev, "tarentry"); err != nil {
893900
errs = append(errs, err)
894901
}
902+
} else if diff := cmp.Diff(ent0.Header.PAXRecords, ent1.Header.PAXRecords, paxOpts...); diff != "" {
903+
ev := Event{
904+
Type: EventTypeTarEntryMismatch,
905+
Inputs: in,
906+
Diff: diff,
907+
Note: fmt.Sprintf("name %q", ent0.Header.Name),
908+
}
909+
if err := d.raiseEvent(ctx, node, ev, "tarentry"); err != nil {
910+
errs = append(errs, err)
911+
}
895912
} else {
896913
// entry matches, so no need to retain the extracted files and dirs
897914
// (but dirs cannot be removed until processing all the tar entries in the layer)

0 commit comments

Comments
 (0)