mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-15 21:28:38 +00:00
8e5c54f51d
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: ed464af779
("*: xattr can Update()")
Signed-off-by: Aleksa Sarai <asarai@suse.de>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package mtree
|
|
|
|
import (
|
|
"io"
|
|
"sort"
|
|
)
|
|
|
|
// DirectoryHierarchy is the mapped structure for an mtree directory hierarchy
|
|
// spec
|
|
type DirectoryHierarchy struct {
|
|
Entries []Entry
|
|
}
|
|
|
|
// WriteTo simplifies the output of the resulting hierarchy spec
|
|
func (dh DirectoryHierarchy) WriteTo(w io.Writer) (n int64, err error) {
|
|
sort.Sort(byPos(dh.Entries))
|
|
var sum int64
|
|
for _, e := range dh.Entries {
|
|
str := e.String()
|
|
i, err := io.WriteString(w, str+"\n")
|
|
if err != nil {
|
|
return sum, err
|
|
}
|
|
sum += int64(i)
|
|
}
|
|
return sum, nil
|
|
}
|
|
|
|
// UsedKeywords collects and returns all the keywords used in a
|
|
// a DirectoryHierarchy
|
|
func (dh DirectoryHierarchy) UsedKeywords() []Keyword {
|
|
usedkeywords := []Keyword{}
|
|
for _, e := range dh.Entries {
|
|
switch e.Type {
|
|
case FullType, RelativeType, SpecialType:
|
|
if e.Type != SpecialType || e.Name == "/set" {
|
|
kvs := e.Keywords
|
|
for _, kv := range kvs {
|
|
kw := KeyVal(kv).Keyword().Prefix()
|
|
if !InKeywordSlice(kw, usedkeywords) {
|
|
usedkeywords = append(usedkeywords, KeywordSynonym(string(kw)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return usedkeywords
|
|
}
|