add lockContentShared
Also, rename lockContent to lockContentExclusive inAnnexSafe should perhaps be eliminated, and instead use `lockContentShared inAnnex`. However, I'm waiting on that, as there are only 2 call sites for inAnnexSafe and it's fiddly.
This commit is contained in:
parent
f52d4b684d
commit
4d50958ed7
11 changed files with 100 additions and 50 deletions
|
@ -88,12 +88,12 @@ startRemote afile numcopies key remote = do
|
|||
showStart' ("drop " ++ Remote.name remote) key afile
|
||||
next $ performRemote key afile numcopies remote
|
||||
|
||||
-- Note that lockContent is called before checking if the key is present
|
||||
-- on enough remotes to allow removal. This avoids a scenario where two
|
||||
-- Note that lockContentExclusive is called before checking if the key is
|
||||
-- present on enough remotes to allow removal. This avoids a scenario where two
|
||||
-- or more remotes are trying to remove a key at the same time, and each
|
||||
-- see the key is present on the other.
|
||||
performLocal :: Key -> AssociatedFile -> NumCopies -> Maybe Remote -> CommandPerform
|
||||
performLocal key afile numcopies knownpresentremote = lockContent key $ \contentlock -> do
|
||||
performLocal key afile numcopies knownpresentremote = lockContentExclusive key $ \contentlock -> do
|
||||
(remotes, trusteduuids) <- Remote.keyPossibilitiesTrusted key
|
||||
let trusteduuids' = case knownpresentremote of
|
||||
Nothing -> trusteduuids
|
||||
|
|
|
@ -31,7 +31,7 @@ start key = stopUnless (inAnnex key) $ do
|
|||
next $ perform key
|
||||
|
||||
perform :: Key -> CommandPerform
|
||||
perform key = lockContent key $ \contentlock -> do
|
||||
perform key = lockContentExclusive key $ \contentlock -> do
|
||||
removeAnnex contentlock
|
||||
next $ cleanup key
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ toPerform dest move key afile fastcheck isthere =
|
|||
finish
|
||||
where
|
||||
finish
|
||||
| move = lockContent key $ \contentlock -> do
|
||||
| move = lockContentExclusive key $ \contentlock -> do
|
||||
removeAnnex contentlock
|
||||
next $ Command.Drop.cleanupLocal key
|
||||
| otherwise = next $ return True
|
||||
|
|
|
@ -120,7 +120,7 @@ test st r k =
|
|||
, check "storeKey when already present" store
|
||||
, present True
|
||||
, check "retrieveKeyFile" $ do
|
||||
lockContent k removeAnnex
|
||||
lockContentExclusive k removeAnnex
|
||||
get
|
||||
, check "fsck downloaded object" fsck
|
||||
, check "retrieveKeyFile resume from 33%" $ do
|
||||
|
@ -130,20 +130,20 @@ test st r k =
|
|||
sz <- hFileSize h
|
||||
L.hGet h $ fromInteger $ sz `div` 3
|
||||
liftIO $ L.writeFile tmp partial
|
||||
lockContent k removeAnnex
|
||||
lockContentExclusive k removeAnnex
|
||||
get
|
||||
, check "fsck downloaded object" fsck
|
||||
, check "retrieveKeyFile resume from 0" $ do
|
||||
tmp <- prepTmp k
|
||||
liftIO $ writeFile tmp ""
|
||||
lockContent k removeAnnex
|
||||
lockContentExclusive k removeAnnex
|
||||
get
|
||||
, check "fsck downloaded object" fsck
|
||||
, check "retrieveKeyFile resume from end" $ do
|
||||
loc <- Annex.calcRepo (gitAnnexLocation k)
|
||||
tmp <- prepTmp k
|
||||
void $ liftIO $ copyFileExternal CopyAllMetaData loc tmp
|
||||
lockContent k removeAnnex
|
||||
lockContentExclusive k removeAnnex
|
||||
get
|
||||
, check "fsck downloaded object" fsck
|
||||
, check "removeKey when present" remove
|
||||
|
@ -189,7 +189,7 @@ testUnavailable st r k =
|
|||
cleanup :: [Remote] -> [Key] -> Bool -> CommandCleanup
|
||||
cleanup rs ks ok = do
|
||||
forM_ rs $ \r -> forM_ ks (Remote.removeKey r)
|
||||
forM_ ks $ \k -> lockContent k removeAnnex
|
||||
forM_ ks $ \k -> lockContentExclusive k removeAnnex
|
||||
return ok
|
||||
|
||||
chunkSizes :: Int -> Bool -> [Int]
|
||||
|
|
|
@ -105,7 +105,7 @@ removeUnannexed = go []
|
|||
go c [] = return c
|
||||
go c (k:ks) = ifM (inAnnexCheck k $ liftIO . enoughlinks)
|
||||
( do
|
||||
lockContent k removeAnnex
|
||||
lockContentExclusive k removeAnnex
|
||||
go c ks
|
||||
, go (k:c) ks
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue