From 3b74386ed4590189509f10206110d9c732a1590d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 30 Aug 2024 14:49:18 -0400 Subject: [PATCH] fix liveupdate locking This fixes the build on windows. Changed it to use lock pools, which will behave better if two threads call getLiveRepoSizes at the same time. Also this should make it work when annex.pidlock is set. In that case, once the current process locks this file, or anything, any other process will have to wait on the pid lock. So checkStaleSizeChanges will correctly identify any other live changes in the database as stale, since there can only be one git-annex process running. --- Annex/LockFile.hs | 16 +++++++++++++++- Annex/RepoSize/LiveUpdate.hs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Annex/LockFile.hs b/Annex/LockFile.hs index 71a07e677c..9e8d1b8105 100644 --- a/Annex/LockFile.hs +++ b/Annex/LockFile.hs @@ -1,6 +1,6 @@ {- git-annex lock files. - - - Copyright 2012-2020 Joey Hess + - Copyright 2012-2024 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -16,6 +16,7 @@ module Annex.LockFile ( withExclusiveLock, takeExclusiveLock, tryExclusiveLock, + trySharedLock, ) where import Annex.Common @@ -111,3 +112,16 @@ tryExclusiveLock lockfile a = debugLocks $ do unlock = maybe noop dropLock go Nothing = return Nothing go (Just _) = Just <$> a + +{- Tries to take a shared lock, without blocking. + - + - Does not create the lock directory or lock file if it does not exist, + - taking an exclusive lock will create them. + -} +trySharedLock :: RawFilePath -> Annex (Maybe LockHandle) +trySharedLock lockfile = debugLocks $ +#ifndef mingw32_HOST_OS + tryLockShared Nothing lockfile +#else + liftIO $ lockShared lockfile +#endif diff --git a/Annex/RepoSize/LiveUpdate.hs b/Annex/RepoSize/LiveUpdate.hs index 49431d0173..dae7abe575 100644 --- a/Annex/RepoSize/LiveUpdate.hs +++ b/Annex/RepoSize/LiveUpdate.hs @@ -177,7 +177,7 @@ checkStaleSizeChanges h@(RepoSizeHandle (Just _) livev) = do checkstale livedir lockfile pid = let f = livedir P. toRawFilePath lockfile - in tryLockShared Nothing f >>= \case + in trySharedLock f >>= \case Nothing -> return Nothing Just lck -> do return $ Just