*: entry linking and keyword filter
Setting up sibling and parent relationships for entries, so they can be easier to walk. Also, making "keyword=value" easier to parse. This helps filtering. Both of these ready us for checking/validating a hierarchy. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
ef9ba54f10
commit
3b6cb6e117
4 changed files with 91 additions and 20 deletions
49
keywords.go
49
keywords.go
|
@ -9,6 +9,7 @@ import (
|
|||
"hash"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
)
|
||||
|
@ -18,6 +19,53 @@ import (
|
|||
// be included for the file entry. Otherwise, empty string.
|
||||
type KeywordFunc func(path string, info os.FileInfo) (string, error)
|
||||
|
||||
// KeyVal is a "keyword=value"
|
||||
type KeyVal string
|
||||
|
||||
// Keyword is the mapping to the available keywords
|
||||
func (kv KeyVal) Keyword() string {
|
||||
if !strings.Contains(string(kv), "=") {
|
||||
return ""
|
||||
}
|
||||
chunks := strings.SplitN(strings.TrimSpace(string(kv)), "=", 2)[0]
|
||||
if !strings.Contains(chunks, ".") {
|
||||
return chunks
|
||||
}
|
||||
return strings.SplitN(chunks, ".", 2)[0]
|
||||
}
|
||||
|
||||
// KeywordSuffix is really only used for xattr, as the keyword is a prefix to
|
||||
// the xattr "namespace.key"
|
||||
func (kv KeyVal) KeywordSuffix() string {
|
||||
if !strings.Contains(string(kv), "=") {
|
||||
return ""
|
||||
}
|
||||
chunks := strings.SplitN(strings.TrimSpace(string(kv)), "=", 2)[0]
|
||||
if !strings.Contains(chunks, ".") {
|
||||
return ""
|
||||
}
|
||||
return strings.SplitN(chunks, ".", 2)[1]
|
||||
}
|
||||
|
||||
// Value is the data/value portion of "keyword=value"
|
||||
func (kv KeyVal) Value() string {
|
||||
if !strings.Contains(string(kv), "=") {
|
||||
return ""
|
||||
}
|
||||
return strings.SplitN(strings.TrimSpace(string(kv)), "=", 2)[1]
|
||||
}
|
||||
|
||||
// keywordSelector takes an array of "keyword=value" and filters out that only the set of words
|
||||
func keywordSelector(keyval, words []string) []string {
|
||||
retList := []string{}
|
||||
for _, kv := range keyval {
|
||||
if inSlice(KeyVal(kv).Keyword(), words) {
|
||||
retList = append(retList, kv)
|
||||
}
|
||||
}
|
||||
return retList
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultKeywords has the several default keyword producers (uid, gid,
|
||||
// mode, nlink, type, size, mtime)
|
||||
|
@ -31,6 +79,7 @@ var (
|
|||
"nlink",
|
||||
"time",
|
||||
}
|
||||
// SetKeywords is the default set of keywords calculated for a `/set` SpecialType
|
||||
SetKeywords = []string{
|
||||
"uid",
|
||||
"gid",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue