summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-10-09 15:48:02 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-10-09 15:48:02 -0400
commit3c43af79d56a25bfff3eae1c1342c9a308223347 (patch)
treee52a095b8963ca42d6530d40bee5858ea8bfcf3c /Command
parente36bfabb0e56087771d385a9f4ecdb342f1f14db (diff)
fix local dropping to not require extra locking of copies, but only that the local copy be locked for removal
Diffstat (limited to 'Command')
-rw-r--r--Command/Drop.hs16
-rw-r--r--Command/DropKey.hs2
-rw-r--r--Command/Import.hs2
-rw-r--r--Command/Move.hs2
-rw-r--r--Command/TestRemote.hs10
-rw-r--r--Command/Uninit.hs2
6 files changed, 16 insertions, 18 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs
index a2bca2204..d14cdad18 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -91,15 +91,11 @@ startRemote afile numcopies key remote = do
showStart' ("drop " ++ Remote.name remote) key afile
next $ performRemote key afile numcopies remote
--- 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
--- sees the key is present on the other.
performLocal :: Key -> AssociatedFile -> NumCopies -> [VerifiedCopy] -> CommandPerform
-performLocal key afile numcopies preverified = lockContentExclusive key $ \contentlock -> do
+performLocal key afile numcopies preverified = lockContentForRemoval key $ \contentlock -> do
u <- getUUID
(tocheck, verified) <- verifiableCopies key [u]
- doDrop u key afile numcopies [] (preverified ++ verified) tocheck
+ doDrop u (Just contentlock) key afile numcopies [] (preverified ++ verified) tocheck
( \proof -> do
liftIO $ debugM "drop" $ unwords
[ "Dropping from here"
@@ -121,7 +117,7 @@ performRemote key afile numcopies remote = do
-- When the local repo has the key, that's one additional copy,
-- as long as the local repo is not untrusted.
(tocheck, verified) <- verifiableCopies key [uuid]
- doDrop uuid key afile numcopies [uuid] verified tocheck
+ doDrop uuid Nothing key afile numcopies [uuid] verified tocheck
( \proof -> do
liftIO $ debugM "drop" $ unwords
[ "Dropping from remote"
@@ -159,6 +155,7 @@ cleanupRemote key remote ok = do
-}
doDrop
:: UUID
+ -> Maybe ContentRemovalLock
-> Key
-> AssociatedFile
-> NumCopies
@@ -167,11 +164,12 @@ doDrop
-> [UnVerifiedCopy]
-> (Maybe SafeDropProof -> CommandPerform, CommandPerform)
-> CommandPerform
-doDrop dropfrom key afile numcopies skip preverified check (dropaction, nodropaction) =
+doDrop dropfrom contentlock key afile numcopies skip preverified check (dropaction, nodropaction) =
ifM (Annex.getState Annex.force)
( dropaction Nothing
, ifM (checkRequiredContent dropfrom key afile)
- ( verifyEnoughCopiesToDrop nolocmsg key numcopies
+ ( verifyEnoughCopiesToDrop nolocmsg key
+ contentlock numcopies
skip preverified check
(dropaction . Just)
(forcehint nodropaction)
diff --git a/Command/DropKey.hs b/Command/DropKey.hs
index cdb19cabb..3dea4b4b7 100644
--- a/Command/DropKey.hs
+++ b/Command/DropKey.hs
@@ -31,7 +31,7 @@ start key = stopUnless (inAnnex key) $ do
next $ perform key
perform :: Key -> CommandPerform
-perform key = lockContentExclusive key $ \contentlock -> do
+perform key = lockContentForRemoval key $ \contentlock -> do
removeAnnex contentlock
next $ cleanup key
diff --git a/Command/Import.hs b/Command/Import.hs
index 5ac050351..a96c08055 100644
--- a/Command/Import.hs
+++ b/Command/Import.hs
@@ -139,5 +139,5 @@ verifyExisting key destfile (yes, no) = do
need <- getFileNumCopies destfile
(tocheck, preverified) <- verifiableCopies key []
- verifyEnoughCopiesToDrop [] key need [] preverified tocheck
+ verifyEnoughCopiesToDrop [] key Nothing need [] preverified tocheck
(const yes) no
diff --git a/Command/Move.hs b/Command/Move.hs
index 072c00663..bd1b6dd92 100644
--- a/Command/Move.hs
+++ b/Command/Move.hs
@@ -123,7 +123,7 @@ toPerform dest move key afile fastcheck isthere =
finish
where
finish
- | move = lockContentExclusive key $ \contentlock -> do
+ | move = lockContentForRemoval key $ \contentlock -> do
removeAnnex contentlock
next $ Command.Drop.cleanupLocal key
| otherwise = next $ return True
diff --git a/Command/TestRemote.hs b/Command/TestRemote.hs
index 3a44a1bde..be1b9a324 100644
--- a/Command/TestRemote.hs
+++ b/Command/TestRemote.hs
@@ -120,7 +120,7 @@ test st r k =
, check "storeKey when already present" store
, present True
, check "retrieveKeyFile" $ do
- lockContentExclusive k removeAnnex
+ lockContentForRemoval 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
- lockContentExclusive k removeAnnex
+ lockContentForRemoval k removeAnnex
get
, check "fsck downloaded object" fsck
, check "retrieveKeyFile resume from 0" $ do
tmp <- prepTmp k
liftIO $ writeFile tmp ""
- lockContentExclusive k removeAnnex
+ lockContentForRemoval 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
- lockContentExclusive k removeAnnex
+ lockContentForRemoval 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 -> lockContentExclusive k removeAnnex
+ forM_ ks $ \k -> lockContentForRemoval k removeAnnex
return ok
chunkSizes :: Int -> Bool -> [Int]
diff --git a/Command/Uninit.hs b/Command/Uninit.hs
index 38e062002..cc237db5e 100644
--- a/Command/Uninit.hs
+++ b/Command/Uninit.hs
@@ -105,7 +105,7 @@ removeUnannexed = go []
go c [] = return c
go c (k:ks) = ifM (inAnnexCheck k $ liftIO . enoughlinks)
( do
- lockContentExclusive k removeAnnex
+ lockContentForRemoval k removeAnnex
go c ks
, go (k:c) ks
)