Skip to content

Commit 8e5c54f

Browse files
committed
compare: correctly use .Prefix() during comparisons
During the rework of how xattr fields are handled, the comparison code was not correctly updated. As a result, changes to xattrs would not be detected in any form. This was detected in the umoci integration suite. In addition, fix the dh.UsedKeywords logic so auto-detection works correctly with prefix-based xattrs. Fixes: ed464af ("*: xattr can Update()") Signed-off-by: Aleksa Sarai <[email protected]>
1 parent ba49f2f commit 8e5c54f

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

compare.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
197197
for _, kv := range oldKeys {
198198
key := kv.Keyword()
199199
// only add this diff if the new keys has this keyword
200-
if key != "tar_time" && key != "time" && key != "xattr" && len(HasKeyword(newKeys, key)) == 0 {
200+
if key != "tar_time" && key != "time" && key.Prefix() != "xattr" && len(HasKeyword(newKeys, key)) == 0 {
201201
continue
202202
}
203203

@@ -216,7 +216,7 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
216216
for _, kv := range newKeys {
217217
key := kv.Keyword()
218218
// only add this diff if the old keys has this keyword
219-
if key != "tar_time" && key != "time" && key != "xattr" && len(HasKeyword(oldKeys, key)) == 0 {
219+
if key != "tar_time" && key != "time" && key.Prefix() != "xattr" && len(HasKeyword(oldKeys, key)) == 0 {
220220
continue
221221
}
222222

@@ -414,7 +414,7 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, er
414414
if keys != nil {
415415
var filterChanged []KeyDelta
416416
for _, keyDiff := range changed {
417-
if InKeywordSlice(keyDiff.name, keys) {
417+
if InKeywordSlice(keyDiff.name.Prefix(), keys) {
418418
filterChanged = append(filterChanged, keyDiff)
419419
}
420420
}

hierarchy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (dh DirectoryHierarchy) UsedKeywords() []Keyword {
3636
if e.Type != SpecialType || e.Name == "/set" {
3737
kvs := e.Keywords
3838
for _, kv := range kvs {
39-
kw := KeyVal(kv).Keyword()
39+
kw := KeyVal(kv).Keyword().Prefix()
4040
if !InKeywordSlice(kw, usedkeywords) {
4141
usedkeywords = append(usedkeywords, KeywordSynonym(string(kw)))
4242
}

hierarchy_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ var checklist = []struct {
2020
.COMMIT_EDITMSG.un~ size=1006 mode=0644 time=1479325423.450468662 sha1digest=dead0face
2121
.TAG_EDITMSG.un~ size=1069 mode=0600 time=1471362316.801317529 sha256digest=dead0face
2222
`, set: []Keyword{"size", "mode", "time", "sha256digest"}},
23+
{blob: `
24+
# user: cyphar
25+
# machine: ryuk
26+
# tree: xattr
27+
# date: Fri Sep 29 21:00:41 2017
28+
# keywords: size,type,uid,gid,mode,link,nlink,time,xattr
29+
30+
# .
31+
/set type=file nlink=1 mode=0664 uid=1000 gid=100 xattr.user.kira=SSdsbCB0YWtlIGEgcG90YXRvIGNoaXAuLi4gYW5kIGVhdCBpdCE=
32+
. size=8 type=dir mode=0755 time=1506666472.255992830
33+
file size=0 mode=0644 time=1506666472.255992830 xattr.user.something=dGVzdA==
34+
..
35+
`, set: []Keyword{"size", "type", "uid", "gid", "mode", "nlink", "time", "xattr"}},
2336
}
2437

2538
func TestUsedKeywords(t *testing.T) {

0 commit comments

Comments
 (0)