Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,14 @@ func (d *differ) loadLayer(ctx context.Context, node *EventTreeNode, inputIdx in
hdr.Name = strings.TrimPrefix(hdr.Name, "./")
hdr.Linkname = strings.TrimPrefix(hdr.Linkname, "/")
hdr.Linkname = strings.TrimPrefix(hdr.Linkname, "./")
if path, ok := hdr.PAXRecords["path"]; ok {
path = strings.TrimPrefix(path, "/")
hdr.PAXRecords["path"] = strings.TrimPrefix(path, "./")
}
if path, ok := hdr.PAXRecords["linkpath"]; ok {
path = strings.TrimPrefix(path, "/")
hdr.PAXRecords["linkpath"] = strings.TrimPrefix(path, "./")
}
}
if os.Geteuid() != 0 && runtime.GOOS == "linux" {
//nolint:staticcheck // SA1019: hdr.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead.
Expand Down Expand Up @@ -868,10 +876,19 @@ func (d *differ) diffTarEntries(ctx context.Context, node *EventTreeNode, in [2]

func (d *differ) diffTarEntry(ctx context.Context, node *EventTreeNode, in [2]EventInput) (dirsToBeRemovedIfEmpty []string, retErr error) {
var negligibleTarFields []string
negligiblePAXFields := map[string]struct{}{}
if d.o.IgnoreFileTimestamps {
negligibleTarFields = append(negligibleTarFields, "ModTime", "AccessTime", "ChangeTime")
negligibleTarFields = append(negligibleTarFields, "ModTime", "AccessTime", "ChangeTime", "PAXRecords")
negligiblePAXFields["mtime"] = struct{}{}
negligiblePAXFields["atime"] = struct{}{}
negligiblePAXFields["ctime"] = struct{}{}
}
discardFunc := func(k, _ string) bool {
_, ok := negligiblePAXFields[k]
return ok
}
cmpOpts := []cmp.Option{cmpopts.IgnoreUnexported(TarEntry{}), cmpopts.IgnoreFields(tar.Header{}, negligibleTarFields...)}
paxOpts := []cmp.Option{cmpopts.IgnoreMapEntries(discardFunc)}
ent0, ent1 := *in[0].TarEntry, *in[1].TarEntry
if d.o.IgnoreFileOrder {
// cmpopts.IgnoreFields cannot be used for int
Expand All @@ -884,6 +901,14 @@ func (d *differ) diffTarEntry(ctx context.Context, node *EventTreeNode, in [2]Ev
ent0.Header.Mode &= 0x0FFF
ent1.Header.Mode &= 0x0FFF
}
pax0 := ent0.Header.PAXRecords
if pax0 == nil {
pax0 = map[string]string{}
}
pax1 := ent1.Header.PAXRecords
if pax1 == nil {
pax1 = map[string]string{}
}
var errs []error
if diff := cmp.Diff(ent0, ent1, cmpOpts...); diff != "" {
ev := Event{
Expand All @@ -895,6 +920,16 @@ func (d *differ) diffTarEntry(ctx context.Context, node *EventTreeNode, in [2]Ev
if err := d.raiseEvent(ctx, node, ev, "tarentry"); err != nil {
errs = append(errs, err)
}
} else if diff := cmp.Diff(pax0, pax1, paxOpts...); diff != "" {
ev := Event{
Type: EventTypeTarEntryMismatch,
Inputs: in,
Diff: diff,
Note: fmt.Sprintf("name %q", ent0.Header.Name),
}
if err := d.raiseEvent(ctx, node, ev, "tarentry"); err != nil {
errs = append(errs, err)
}
} else {
// entry matches, so no need to retain the extracted files and dirs
// (but dirs cannot be removed until processing all the tar entries in the layer)
Expand Down