fix too early close of shared lock file

This fixes a reversion introduced in commit
ac56a5c2a0.

I didn't notice there that it was handling the case of a shared lock
file that was still open elsewhere by not running the close action.

This was especially deadly when annex.pidlock is set, as it caused early
deletion of the pid lock file.

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2021-12-01 16:57:56 -04:00
parent f50de2455f
commit 66b2536ea0
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 6 additions and 5 deletions

View file

@ -6,6 +6,7 @@ git-annex (8.20211124) UNRELEASED; urgency=medium
erroring out.
* export: Avoid unncessarily re-exporting non-annexed files that were
already exported.
* Fix locking bug introduced in version 8.20200814.
-- Joey Hess <id@joeyh.name> Tue, 23 Nov 2021 15:58:27 -0400

View file

@ -122,15 +122,15 @@ releaseLock :: LockHandle -> IO ()
releaseLock h = go =<< atomically (tryTakeTMVar h)
where
go (Just (pool, file, closelockfile)) = do
m <- atomically $ do
(m, lastuser) <- atomically $ do
m <- takeTMVar pool
return $ case M.lookup file m of
Just (LockStatus mode n)
| n == 1 -> (M.delete file m)
| n == 1 -> (M.delete file m, True)
| otherwise ->
(M.insert file (LockStatus mode (pred n)) m)
Nothing -> m
() <- closelockfile
(M.insert file (LockStatus mode (pred n)) m, False)
Nothing -> (m, True)
() <- when lastuser closelockfile
atomically $ putTMVar pool m
-- The LockHandle was already closed.
go Nothing = return ()