forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta-node.go
52 lines (44 loc) · 1.16 KB
/
meta-node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package merger
import (
"path"
"regexp"
"github.com/gobwas/glob"
"github.com/pydio/cells/common/proto/tree"
)
const (
NodeType_METADATA tree.NodeType = 3
MetaNodeParentUUIDMeta = "ParentUUID"
MetaNodeParentPathMeta = "ParentPath"
)
type MetaConfig struct {
MetaNames []string
MetaRegexp []*regexp.Regexp
}
// newMetaNode create a new MetaNode from an existing metadata
func newMetaNode(parentNode *TreeNode, name, value string) *TreeNode {
tN := NewTreeNode(&tree.Node{
Path: path.Join(parentNode.Path, name),
Uuid: parentNode.Uuid + "-" + name,
Type: NodeType_METADATA,
Etag: value,
MetaStore: map[string]string{
MetaNodeParentUUIDMeta: `"` + parentNode.Uuid + `"`, // Json-encode parent Uuid
MetaNodeParentPathMeta: `"` + parentNode.Path + `"`, // Json-encode parent Path
},
})
return tN
}
// addMetadataAsChildNodes extracts MetaNodes from normal node, based on a config
func addMetadataAsChildNodes(n *TreeNode, metaGlobs []glob.Glob) {
if len(metaGlobs) == 0 || n.MetaStore == nil {
return
}
for k, v := range n.MetaStore {
for _, g := range metaGlobs {
if g.Match(k) {
n.AddChild(newMetaNode(n, k, v))
}
}
}
return
}