summaryrefslogtreecommitdiff
path: root/Command/Drop.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-09 16:54:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-09 16:54:18 -0400
commit8ce7e73f74e95276472d18816b7c6a60bab25abb (patch)
treef4a29907c46af2735411fe9fcbeca0f9c3149cab /Command/Drop.hs
parent58563c5b1aa995ea3ce72cddaa1f02d2ea792c2d (diff)
reorg to allow taking content lock
The lock will only persist during the perform stage, so the content must be removed from the annex then, rather than in the cleanup stage. (No lock is actually taken yet.)
Diffstat (limited to 'Command/Drop.hs')
-rw-r--r--Command/Drop.hs18
1 files changed, 10 insertions, 8 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 2267bd941..e81bd9d7d 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -52,17 +52,19 @@ startRemote file numcopies key remote = do
next $ performRemote key numcopies remote
performLocal :: Key -> Maybe Int -> CommandPerform
-performLocal key numcopies = do
+performLocal key numcopies = lockExclusive key $ do
(remotes, trusteduuids) <- Remote.keyPossibilitiesTrusted key
untrusteduuids <- trustGet UnTrusted
let tocheck = Remote.remotesWithoutUUID remotes (trusteduuids++untrusteduuids)
success <- canDropKey key numcopies trusteduuids tocheck []
if success
- then next $ cleanupLocal key
+ then do
+ whenM (inAnnex key) $ removeAnnex key
+ next $ cleanupLocal key
else stop
performRemote :: Key -> Maybe Int -> Remote.Remote Annex -> CommandPerform
-performRemote key numcopies remote = do
+performRemote key numcopies remote = lockExclusive key $ 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.
@@ -76,20 +78,20 @@ performRemote key numcopies remote = do
Remote.remotesWithoutUUID remotes (have++untrusteduuids)
success <- canDropKey key numcopies have tocheck [uuid]
if success
- then next $ cleanupRemote key remote
+ then do
+ ok <- Remote.removeKey remote key
+ next $ cleanupRemote key remote ok
else stop
where
uuid = Remote.uuid remote
cleanupLocal :: Key -> CommandCleanup
cleanupLocal key = do
- whenM (inAnnex key) $ removeAnnex key
logStatus key InfoMissing
return True
-cleanupRemote :: Key -> Remote.Remote Annex -> CommandCleanup
-cleanupRemote key remote = do
- ok <- Remote.removeKey remote key
+cleanupRemote :: Key -> Remote.Remote Annex -> Bool -> CommandCleanup
+cleanupRemote key remote ok = do
-- better safe than sorry: assume the remote dropped the key
-- even if it seemed to fail; the failure could have occurred
-- after it really dropped it