Skip to content

Commit

Permalink
Merge pull request #4291 from kobergj/ReleaseLockWhenExpired
Browse files Browse the repository at this point in the history
Release expired locks when statting
  • Loading branch information
kobergj authored Oct 27, 2023
2 parents fdeb764 + c901032 commit 97810a2
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, false)
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 97810a2

Please sign in to comment.