Skip to content

Commit

Permalink
decomposedfs: use checkLock() in the rest of cases
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 Feb 1, 2022
1 parent c21e25f commit ade962a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 72 deletions.
15 changes: 4 additions & 11 deletions pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/storage/utils/ace"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
Expand Down Expand Up @@ -64,11 +63,8 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g
}

// check lock
if lock := node.ReadLock(ctx); lock != nil {
lockID, _ := ctxpkg.ContextGetLockID(ctx)
if lock.LockId != lockID {
return errtypes.Locked(lock.LockId)
}
if err := fs.checkLock(ctx, node); err != nil {
return err
}

np := fs.lu.InternalPath(node.ID)
Expand Down Expand Up @@ -152,11 +148,8 @@ func (fs *Decomposedfs) RemoveGrant(ctx context.Context, ref *provider.Reference
}

// check lock
if lock := node.ReadLock(ctx); lock != nil {
lockID, _ := ctxpkg.ContextGetLockID(ctx)
if lock.LockId != lockID {
return errtypes.Locked(lock.LockId)
}
if err := fs.checkLock(ctx, node); err != nil {
return err
}

var attr string
Expand Down
14 changes: 4 additions & 10 deletions pkg/storage/utils/decomposedfs/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ func (fs *Decomposedfs) SetArbitraryMetadata(ctx context.Context, ref *provider.
}

// check lock
if lock := n.ReadLock(ctx); lock != nil {
lockID, _ := ctxpkg.ContextGetLockID(ctx)
if lock.LockId != lockID {
return errtypes.Locked(lock.LockId)
}
if err := fs.checkLock(ctx, n); err != nil {
return err
}

nodePath := n.InternalPath()
Expand Down Expand Up @@ -157,11 +154,8 @@ func (fs *Decomposedfs) UnsetArbitraryMetadata(ctx context.Context, ref *provide
}

// check lock
if lock := n.ReadLock(ctx); lock != nil {
lockID, _ := ctxpkg.ContextGetLockID(ctx)
if lock.LockId != lockID {
return errtypes.Locked(lock.LockId)
}
if err := fs.checkLock(ctx, n); err != nil {
return err
}

nodePath := n.InternalPath()
Expand Down
1 change: 0 additions & 1 deletion pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ func readLocksIntoOpaque(ctx context.Context, lockPath string, ri *provider.Reso

// ReadLock reads the lock id for a node
func (n Node) ReadLock(ctx context.Context) *provider.Lock {
// check lock
lockPath := n.InternalPath() + ".lock"

f, err := os.Open(lockPath)
Expand Down
8 changes: 2 additions & 6 deletions pkg/storage/utils/decomposedfs/recycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs"
Expand Down Expand Up @@ -281,11 +280,8 @@ func (fs *Decomposedfs) RestoreRecycleItem(ctx context.Context, ref *provider.Re
}

// check lock
if lock := targetNode.ReadLock(ctx); lock != nil {
lockID, _ := ctxpkg.ContextGetLockID(ctx)
if lock.LockId != lockID {
return errtypes.Locked(lock.LockId)
}
if err := fs.checkLock(ctx, targetNode); err != nil {
return err
}

// Run the restore func
Expand Down
8 changes: 2 additions & 6 deletions pkg/storage/utils/decomposedfs/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
"github.com/pkg/errors"
Expand Down Expand Up @@ -167,11 +166,8 @@ func (fs *Decomposedfs) RestoreRevision(ctx context.Context, ref *provider.Refer
}

// check lock
if lock := n.ReadLock(ctx); lock != nil {
lockID, _ := ctxpkg.ContextGetLockID(ctx)
if lock.LockId != lockID {
return errtypes.Locked(lock.LockId)
}
if err := fs.checkLock(ctx, n); err != nil {
return err
}

// move current version to new revision
Expand Down
42 changes: 4 additions & 38 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,8 @@ func (fs *Decomposedfs) NewUpload(ctx context.Context, info tusd.FileInfo) (uplo
}

// check lock
lockPath := n.InternalPath() + ".lock"

f, err := os.Open(lockPath)
switch {
case err == nil:
defer f.Close()

lock := &provider.Lock{}
if err := json.NewDecoder(f).Decode(lock); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: could not read lock file")
}
u := ctxpkg.ContextMustGetUser(ctx)
if !utils.UserEqual(lock.GetUser(), u.Id) {
return nil, errtypes.PermissionDenied("locked by " + lock.GetUser().String())
}
case os.IsNotExist(err):
// ok
default:
return nil, errtypes.NotFound("could not open existing lock file")
if err := fs.checkLock(ctx, n); err != nil {
return nil, err
}

info.ID = uuid.New().String()
Expand Down Expand Up @@ -492,25 +475,8 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) (err error) {
n.SpaceRoot = node.New(upload.info.Storage["SpaceRoot"], "", "", 0, "", nil, upload.fs.lu)

// check lock
lockPath := n.InternalPath() + ".lock"

f, err := os.Open(lockPath)
switch {
case err == nil:
defer f.Close()

lock := &provider.Lock{}
if err := json.NewDecoder(f).Decode(lock); err != nil {
return errors.Wrap(err, "Decomposedfs: could not read lock file")
}
u := ctxpkg.ContextMustGetUser(ctx)
if !utils.UserEqual(lock.GetUser(), u.Id) {
return errtypes.PermissionDenied("locked by " + lock.GetUser().String())
}
case os.IsNotExist(err):
// ok
default:
return errtypes.NotFound("could not open existing lock file")
if err := upload.fs.checkLock(ctx, n); err != nil {
return err
}

_, err = node.CheckQuota(n.SpaceRoot, uint64(fi.Size()))
Expand Down

0 comments on commit ade962a

Please sign in to comment.