1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-10-04 04:31:00 +00:00

compare: move FreeBSD loose keyword comparisons to gomtree command

FreeBSD has quite unfortunate behaviour when dealing with keywords that
are missing in one of the manifests being compared -- namely, they
ignore these instances.

Commit 21723a3974 ("*: fix comparison of missing keywords") re-added
this behaviour after the introduction of the Compare API, but
unfortunately it was implemented in the Compare API itself -- meaning
that library users (which didn't want this behaviour) were silently
opted into it.

This patch moves the behaviour to the command-line, where it belongs
(a future patch in this series will allow users to opt-out of this
unfortunate behaviour, as well as some other unfortunate FreeBSD
compatibility behaviours).

Fixes: 21723a3974 ("*: fix comparison of missing keywords")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai 2025-09-16 22:27:20 +10:00
parent ae454c4a6f
commit 1ce6aa8db5
No known key found for this signature in database
GPG key ID: 2897FAD2B7E9446F
3 changed files with 92 additions and 26 deletions

View file

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"iter"
"maps"
"slices"
"github.com/sirupsen/logrus"
@ -247,31 +246,6 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
newKeys = newEntry.allKeysMap()
)
// Delete any keys which are not present in both maps.
keyFilterFn := func(otherMap map[Keyword]KeyVal) func(Keyword, KeyVal) bool {
return func(k Keyword, _ KeyVal) bool {
switch {
case k.Prefix() == "xattr":
// xattrs are presented as one keyword to users but are actually
// implemented as separate keywords and so we should always include
// them (even if the same xattr is not present in both sides).
// TODO: I actually think this is not inline with the original
// purpose of this code, but I'm leaving it as-is to not not
// introduce bugs.
return false
case k == "time" || k == "tar_time":
// These have special handling later.
return false
default:
// Drop keys which do not exist in the other entry.
_, ok := otherMap[k]
return !ok
}
}
}
maps.DeleteFunc(oldKeys, keyFilterFn(newKeys))
maps.DeleteFunc(newKeys, keyFilterFn(oldKeys))
// If both tar_time and time were specified in the set of keys, we have to
// convert the "time" entries to "tar_time" to allow for tar archive
// manifests to be compared with proper filesystem manifests.