Skip to content

Commit

Permalink
set and unset 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 10, 2020
1 parent f0e2ae6 commit e0dcb28
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
39 changes: 37 additions & 2 deletions pkg/storage/fs/ocis/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,50 @@ package ocis

import (
"context"
"path/filepath"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/pkg/errors"
"github.com/pkg/xattr"
)

func (fs *ocisfs) SetArbitraryMetadata(ctx context.Context, ref *provider.Reference, md *provider.ArbitraryMetadata) (err error) {
return errtypes.NotSupported("operation not supported: SetArbitraryMetadata")
n, err := fs.pw.NodeFromResource(ctx, ref)
if err != nil {
return errors.Wrap(err, "ocisfs: error resolving ref")
}

if !n.Exists {
err = errtypes.NotFound(filepath.Join(n.ParentID, n.Name))
return err
}
nodePath := filepath.Join(fs.pw.Root, "nodes", n.ID)
for k, v := range md.Metadata {
attrName := metadataPrefix + k
if err = xattr.Set(nodePath, attrName, []byte(v)); err != nil {
return errors.Wrap(err, "ocisfs: could not set metadata attribute "+attrName+" to "+k)
}
}
return
}

func (fs *ocisfs) UnsetArbitraryMetadata(ctx context.Context, ref *provider.Reference, keys []string) (err error) {
return errtypes.NotSupported("operation not supported: UnsetArbitraryMetadata")
n, err := fs.pw.NodeFromResource(ctx, ref)
if err != nil {
return errors.Wrap(err, "ocisfs: error resolving ref")
}

if !n.Exists {
err = errtypes.NotFound(filepath.Join(n.ParentID, n.Name))
return err
}
nodePath := filepath.Join(fs.pw.Root, "nodes", n.ID)
for i := range keys {
attrName := metadataPrefix + keys[i]
if err = xattr.Remove(nodePath, attrName); err != nil {
return errors.Wrap(err, "ocisfs: could not remove metadata attribute "+attrName)
}
}
return
}
3 changes: 2 additions & 1 deletion pkg/storage/fs/ocis/ocis.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const (
// "user.ocis."

// SharePrefix is the prefix for sharing related extended attributes
sharePrefix string = "user.ocis.acl."
sharePrefix string = "user.ocis.acl."
metadataPrefix string = "user.ocis.md."
// TODO implement favorites metadata flag
//favPrefix string = "user.ocis.fav." // favorite flag, per user
// TODO use etag prefix instead of single etag property
Expand Down

0 comments on commit e0dcb28

Please sign in to comment.