Skip to content

Commit

Permalink
release an expired lock on stat
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Oct 27, 2023
1 parent a0a3e4f commit b7a7b8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/release-lock-when-expired.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Release lock when expired

Release an expired lock when stating the resource

https://github.com/cs3org/reva/pull/4291
30 changes: 2 additions & 28 deletions pkg/storage/utils/decomposedfs/node/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,38 +276,12 @@ func (n *Node) CheckLock(ctx context.Context) error {
}

func readLocksIntoOpaque(ctx context.Context, n *Node, ri *provider.ResourceInfo) error {

// ensure parent path exists
if err := os.MkdirAll(filepath.Dir(n.InternalPath()), 0700); err != nil {
return errors.Wrap(err, "Decomposedfs: error creating parent folder for lock")
}
fileLock, err := filelocks.AcquireReadLock(n.InternalPath())

lock, err := n.ReadLock(ctx, true)
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Msg("Decomposedfs: could not read lock")
return err
}

defer func() {
rerr := filelocks.ReleaseLock(fileLock)

// if err is non nil we do not overwrite that
if err == nil {
err = rerr
}
}()

f, err := os.Open(n.LockFilePath())
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Msg("Decomposedfs: could not open lock file")
return err
}
defer f.Close()

lock := &provider.Lock{}
if err := json.NewDecoder(f).Decode(lock); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Msg("Decomposedfs: could not read lock file")
}

// reencode to ensure valid json
var b []byte
if b, err = json.Marshal(lock); err != nil {
Expand Down

0 comments on commit b7a7b8b

Please sign in to comment.