Skip to content

Commit

Permalink
read metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Sep 11, 2020
1 parent 16cb048 commit a03af64
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/storage/fs/ocis/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ func (n *Node) Owner() (id string, idp string, err error) {

// AsResourceInfo return the node as CS3 ResourceInfo
func (n *Node) AsResourceInfo(ctx context.Context) (ri *provider.ResourceInfo, err error) {
var fn string
log := appctx.GetLogger(ctx)

var fn string
nodePath := filepath.Join(n.pw.Root, "nodes", n.ID)

var fi os.FileInfo
Expand Down Expand Up @@ -232,7 +233,6 @@ func (n *Node) AsResourceInfo(ctx context.Context) (ri *provider.ResourceInfo, e
var etag []byte
// TODO optionally store etag in new `root/attributes/<uuid>` file
if etag, err = xattr.Get(nodePath, "user.ocis.etag"); err != nil {
log := appctx.GetLogger(ctx)
log.Error().Err(err).Interface("node", n).Msg("could not read etag")
}

Expand Down Expand Up @@ -264,7 +264,26 @@ func (n *Node) AsResourceInfo(ctx context.Context) (ri *provider.ResourceInfo, e
OpaqueId: owner,
}
}
log := appctx.GetLogger(ctx)

// TODO only read the requested metadata attributes
if attrs, err := xattr.List(nodePath); err == nil {
ri.ArbitraryMetadata = &provider.ArbitraryMetadata{
Metadata: map[string]string{},
}
for i := range attrs {
if strings.HasPrefix(attrs[i], metadataPrefix) {
k := strings.TrimPrefix(attrs[i], metadataPrefix)
if v, err := xattr.Get(nodePath, attrs[i]); err == nil {
ri.ArbitraryMetadata.Metadata[k] = string(v)
} else {
log.Error().Err(err).Interface("node", n).Str("attr", attrs[i]).Msg("could not get attribute value")
}
}
}
} else {
log.Error().Err(err).Interface("node", n).Msg("could not list attributes")
}

log.Debug().
Interface("ri", ri).
Msg("AsResourceInfo")
Expand Down

0 comments on commit a03af64

Please sign in to comment.