summaryrefslogtreecommitdiff
path: root/Command/Drop.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-20 20:08:45 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-20 20:13:47 -0400
commit28ac29b518a49363788b3607130cee5aff5534e9 (patch)
tree25985e4f7937c64e662ef5447651f4e44d2b9cbf /Command/Drop.hs
parent6f8f6b7dde108168ac5a9f0b3fb2cb8ea2d2f60c (diff)
use types to enforce that removeAnnex can only be called inside lockContent
This fixed one bug where it needed to be and wasn't (in Assistant.Unused). And also found one place where lockContent was used unnecessarily (by drop --from remote). A few other places like uninit probably don't really need to lockContent, but it doesn't hurt to do call it anyway. This commit was sponsored by David Wagner.
Diffstat (limited to 'Command/Drop.hs')
-rw-r--r--Command/Drop.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 4bac07a53..cf63d2bc7 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -55,8 +55,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
+-- 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 $ do
+performLocal key afile numcopies knownpresentremote = lockContent key $ \contentlock -> do
(remotes, trusteduuids) <- Remote.keyPossibilitiesTrusted key
let trusteduuids' = case knownpresentremote of
Nothing -> trusteduuids
@@ -66,7 +70,7 @@ performLocal key afile numcopies knownpresentremote = lockContent key $ do
u <- getUUID
ifM (canDrop u key afile numcopies trusteduuids' tocheck [])
( do
- removeAnnex key
+ removeAnnex contentlock
notifyDrop afile True
next $ cleanupLocal key
, do
@@ -75,7 +79,7 @@ performLocal key afile numcopies knownpresentremote = lockContent key $ do
)
performRemote :: Key -> AssociatedFile -> NumCopies -> Remote -> CommandPerform
-performRemote key afile numcopies remote = lockContent key $ do
+performRemote key afile numcopies remote = do
-- Filter the remote it's being dropped from out of the lists of
-- places assumed to have the key, and places to check.
-- When the local repo has the key, that's one additional copy,