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

@ -368,6 +368,7 @@ func validateAction(c *cli.Context) error {
if isTarSpec(specDh) || c.String("tar") != "" {
filters = append(filters, tarKeywordFilter)
}
filters = append(filters, freebsdCompatKeywordFilter)
res = filterDeltas(res, filters...)
if len(res) > 0 {
@ -458,6 +459,25 @@ func tarKeywordFilter(delta *mtree.InodeDelta) bool {
return true
}
// freebsdCompatKeywordFilter removes any deltas where a key is not present in
// both manifests being compared. This is necessary for compatibility with
// FreeBSD's mtree(8) but is generally undesireable for most users.
func freebsdCompatKeywordFilter(delta *mtree.InodeDelta) bool {
if delta.Type() != mtree.Modified {
return true
}
keys := delta.DiffPtr()
*keys = slices.DeleteFunc(*keys, func(kd mtree.KeyDelta) bool {
if kd.Name().Prefix() == "xattr" {
// Even in FreeBSD compatibility mode, any xattr changes should
// still be treated as a proper change and not filtered out.
return false
}
return kd.Type() != mtree.Modified
})
return true
}
type deltaFilterFn func(*mtree.InodeDelta) bool
// filterDeltas takes the set of deltas generated by mtree and applies the