From 164632b889fd92d450945b61eb7eec00c0449e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 10 Sep 2020 22:56:56 +0200 Subject: [PATCH] read metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- pkg/storage/fs/ocis/node.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pkg/storage/fs/ocis/node.go b/pkg/storage/fs/ocis/node.go index c96da222f14..eae9e4484be 100644 --- a/pkg/storage/fs/ocis/node.go +++ b/pkg/storage/fs/ocis/node.go @@ -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 @@ -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/` 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") } @@ -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")