diff --git a/pkg/storage/fs/ocis/node.go b/pkg/storage/fs/ocis/node.go index 3d15fd43c28..1b763dd16ba 100644 --- a/pkg/storage/fs/ocis/node.go +++ b/pkg/storage/fs/ocis/node.go @@ -148,10 +148,16 @@ func ReadNode(ctx context.Context, lu *Lookup, id string) (n *Node, err error) { // lookup parent id in extended attributes var attrBytes []byte - if attrBytes, err = xattr.Get(nodePath, parentidAttr); err == nil { + attrBytes, err = xattr.Get(nodePath, parentidAttr) + switch { + case err == nil: n.ParentID = string(attrBytes) - } else { - return + case isNoData(err): + return nil, errtypes.InternalError(err.Error()) + case isNotFound(err): + return nil, errtypes.NotFound(n.ID) + default: + return nil, errtypes.InternalError(err.Error()) } // lookup name in extended attributes if attrBytes, err = xattr.Get(nodePath, nameAttr); err == nil { diff --git a/pkg/storage/fs/ocis/ocis.go b/pkg/storage/fs/ocis/ocis.go index bd1eb9e94ec..8d41907cb89 100644 --- a/pkg/storage/fs/ocis/ocis.go +++ b/pkg/storage/fs/ocis/ocis.go @@ -224,16 +224,19 @@ func (fs *ocisfs) GetPathByID(ctx context.Context, id *provider.ResourceId) (str } func (fs *ocisfs) CreateDir(ctx context.Context, fn string) (err error) { - var node *Node - if node, err = fs.lu.NodeFromPath(ctx, fn); err != nil { + var n *Node + if n, err = fs.lu.NodeFromPath(ctx, fn); err != nil { return } - if node.Exists { + if n.Exists { return errtypes.AlreadyExists(fn) } - pn, err := node.Parent() + pn, err := n.Parent() + if err != nil { + return errors.Wrap(err, "ocisfs: error getting parent "+n.ParentID) + } ok, err := fs.p.HasPermission(ctx, pn, func(rp *provider.ResourcePermissions) bool { return rp.CreateContainer }) @@ -241,16 +244,16 @@ func (fs *ocisfs) CreateDir(ctx context.Context, fn string) (err error) { case err != nil: return errtypes.InternalError(err.Error()) case !ok: - return errtypes.PermissionDenied(filepath.Join(node.ParentID, node.Name)) + return errtypes.PermissionDenied(filepath.Join(n.ParentID, n.Name)) } - err = fs.tp.CreateDir(ctx, node) + err = fs.tp.CreateDir(ctx, n) if fs.o.TreeTimeAccounting { - nodePath := node.lu.toInternalPath(node.ID) + nodePath := n.lu.toInternalPath(n.ID) // mark the home node as the end of propagation if err = xattr.Set(nodePath, propagationAttr, []byte("1")); err != nil { - appctx.GetLogger(ctx).Error().Err(err).Interface("node", node).Msg("could not mark node to propagate") + appctx.GetLogger(ctx).Error().Err(err).Interface("node", n).Msg("could not mark node to propagate") return } } diff --git a/pkg/storage/fs/ocis/option.go b/pkg/storage/fs/ocis/option.go index 198075d979c..e8ee62464a7 100644 --- a/pkg/storage/fs/ocis/option.go +++ b/pkg/storage/fs/ocis/option.go @@ -43,6 +43,7 @@ type Options struct { } // newOptions initializes the available default options. +/* for future use, commented to make linter happy func newOptions(opts ...Option) Options { opt := Options{} @@ -52,6 +53,7 @@ func newOptions(opts ...Option) Options { return opt } +*/ // Root provides a function to set the root option. func Root(val string) Option { diff --git a/pkg/storage/fs/ocis/permissions.go b/pkg/storage/fs/ocis/permissions.go index fef8e60e988..6dcfd9c4e30 100644 --- a/pkg/storage/fs/ocis/permissions.go +++ b/pkg/storage/fs/ocis/permissions.go @@ -26,8 +26,8 @@ import ( userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" - "github.com/cs3org/reva/pkg/storage/utils/ace" "github.com/cs3org/reva/pkg/user" + "github.com/pkg/errors" "github.com/pkg/xattr" ) @@ -136,7 +136,7 @@ func (p *Permissions) HasPermission(ctx context.Context, n *Node, check func(*pr } if cn, err = cn.Parent(); err != nil { - return false, err + return false, errors.Wrap(err, "ocisfs: error getting parent "+cn.ParentID) } } @@ -185,14 +185,3 @@ func isNotFound(err error) bool { } return false } - -func (fs *ocisfs) readACE(ctx context.Context, ip string, principal string) (e *ace.ACE, err error) { - var b []byte - if b, err = xattr.Get(ip, grantPrefix+principal); err != nil { - return nil, err - } - if e, err = ace.Unmarshal(principal, b); err != nil { - return nil, err - } - return -} diff --git a/pkg/storage/fs/ocis/revisions.go b/pkg/storage/fs/ocis/revisions.go index 816aa6c1ea6..898cd5c3487 100644 --- a/pkg/storage/fs/ocis/revisions.go +++ b/pkg/storage/fs/ocis/revisions.go @@ -90,6 +90,9 @@ func (fs *ocisfs) DownloadRevision(ctx context.Context, ref *provider.Reference, // check if the node is available and has not been deleted n, err := ReadNode(ctx, fs.lu, kp[0]) + if err != nil { + return nil, err + } if !n.Exists { err = errtypes.NotFound(filepath.Join(n.ParentID, n.Name)) return nil, err @@ -130,6 +133,9 @@ func (fs *ocisfs) RestoreRevision(ctx context.Context, ref *provider.Reference, // check if the node is available and has not been deleted n, err := ReadNode(ctx, fs.lu, kp[0]) + if err != nil { + return err + } if !n.Exists { err = errtypes.NotFound(filepath.Join(n.ParentID, n.Name)) return err diff --git a/pkg/storage/fs/ocis/tree.go b/pkg/storage/fs/ocis/tree.go index 63cb090935e..f58390cabe5 100644 --- a/pkg/storage/fs/ocis/tree.go +++ b/pkg/storage/fs/ocis/tree.go @@ -225,12 +225,12 @@ func (t *Tree) ListFolder(ctx context.Context, node *Node) ([]*Node, error) { } // Delete deletes a node in the tree -func (t *Tree) Delete(ctx context.Context, node *Node) (err error) { +func (t *Tree) Delete(ctx context.Context, n *Node) (err error) { // Prepare the trash // TODO use layout?, but it requires resolving the owners user if the username is used instead of the id. // the node knows the owner id so we use that for now - ownerid, _, err := node.Owner() + ownerid, _, err := n.Owner() if err != nil { return } @@ -244,13 +244,13 @@ func (t *Tree) Delete(ctx context.Context, node *Node) (err error) { } // get the original path - origin, err := t.lu.Path(ctx, node) + origin, err := t.lu.Path(ctx, n) if err != nil { return } // set origin location in metadata - nodePath := t.lu.toInternalPath(node.ID) + nodePath := t.lu.toInternalPath(n.ID) if err := xattr.Set(nodePath, trashOriginAttr, []byte(origin)); err != nil { return err } @@ -259,8 +259,8 @@ func (t *Tree) Delete(ctx context.Context, node *Node) (err error) { // first make node appear in the owners (or root) trash // parent id and name are stored as extended attributes in the node itself - trashLink := filepath.Join(t.lu.Options.Root, "trash", ownerid, node.ID) - err = os.Symlink("../nodes/"+node.ID+".T."+deletionTime, trashLink) + trashLink := filepath.Join(t.lu.Options.Root, "trash", ownerid, n.ID) + err = os.Symlink("../nodes/"+n.ID+".T."+deletionTime, trashLink) if err != nil { // To roll back changes // TODO unset trashOriginAttr @@ -280,7 +280,7 @@ func (t *Tree) Delete(ctx context.Context, node *Node) (err error) { } // finally remove the entry from the parent dir - src := filepath.Join(t.lu.toInternalPath(node.ParentID), node.Name) + src := filepath.Join(t.lu.toInternalPath(n.ParentID), n.Name) err = os.Remove(src) if err != nil { // To roll back changes @@ -290,9 +290,9 @@ func (t *Tree) Delete(ctx context.Context, node *Node) (err error) { return } - p, err := node.Parent() + p, err := n.Parent() if err != nil { - return + return errors.Wrap(err, "ocisfs: error getting parent "+n.ParentID) } return t.Propagate(ctx, p) } diff --git a/pkg/storage/fs/ocis/upload.go b/pkg/storage/fs/ocis/upload.go index ec065838e78..335aeb2aaec 100644 --- a/pkg/storage/fs/ocis/upload.go +++ b/pkg/storage/fs/ocis/upload.go @@ -44,11 +44,11 @@ var defaultFilePerm = os.FileMode(0664) // TODO deprecated ... use tus -func (fs *ocisfs) Upload(ctx context.Context, ref *provider.Reference, r io.ReadCloser) error { +func (fs *ocisfs) Upload(ctx context.Context, ref *provider.Reference, r io.ReadCloser) (err error) { - n, err := fs.lu.NodeFromResource(ctx, ref) - if err != nil { - return err + var n *Node + if n, err = fs.lu.NodeFromResource(ctx, ref); err != nil { + return } // check permissions @@ -60,9 +60,9 @@ func (fs *ocisfs) Upload(ctx context.Context, ref *provider.Reference, r io.Read }) } else { // check permissions of parent - p, err := n.Parent() - if err != nil { - return errors.Wrap(err, "ocisfs: error getting parent "+n.ParentID) + p, perr := n.Parent() + if perr != nil { + return errors.Wrap(perr, "ocisfs: error getting parent "+n.ParentID) } ok, err = fs.p.HasPermission(ctx, p, func(rp *provider.ResourcePermissions) bool { @@ -82,7 +82,8 @@ func (fs *ocisfs) Upload(ctx context.Context, ref *provider.Reference, r io.Read nodePath := fs.lu.toInternalPath(n.ID) - tmp, err := ioutil.TempFile(nodePath, "._reva_atomic_upload") + var tmp *os.File + tmp, err = ioutil.TempFile(nodePath, "._reva_atomic_upload") if err != nil { return errors.Wrap(err, "ocisfs: error creating tmp fn at "+nodePath) } @@ -96,9 +97,8 @@ func (fs *ocisfs) Upload(ctx context.Context, ref *provider.Reference, r io.Read //_ = os.RemoveAll(path.Join(nodePath, "content")) appctx.GetLogger(ctx).Warn().Msg("TODO move old content to version") - err = os.Rename(tmp.Name(), nodePath) - if err != nil { - return err + if err = os.Rename(tmp.Name(), nodePath); err != nil { + return } if fs.o.EnableHome { @@ -113,19 +113,18 @@ func (fs *ocisfs) Upload(ctx context.Context, ref *provider.Reference, r io.Read err = n.writeMetadata(nil) } if err != nil { - return err + return } if fs.o.TreeTimeAccounting { // mark the home node as the end of propagation q if err = xattr.Set(nodePath, propagationAttr, []byte("1")); err != nil { appctx.GetLogger(ctx).Error().Err(err).Interface("node", n).Msg("could not mark node to propagate") - return err + return } } return fs.tp.Propagate(ctx, n) - } // InitiateUpload returns an upload id that can be used for uploads with tus @@ -217,9 +216,9 @@ func (fs *ocisfs) NewUpload(ctx context.Context, info tusd.FileInfo) (upload tus }) } else { // check permissions of parent - p, err := n.Parent() - if err != nil { - return nil, errors.Wrap(err, "ocisfs: error getting parent "+n.ParentID) + p, perr := n.Parent() + if perr != nil { + return nil, errors.Wrap(perr, "ocisfs: error getting parent "+n.ParentID) } ok, err = fs.p.HasPermission(ctx, p, func(rp *provider.ResourcePermissions) bool {