aboutsummaryrefslogtreecommitdiff
path: root/Assistant/DeleteRemote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-04-03 19:03:16 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-04-03 19:03:16 -0400
commit1de27dbbbe6fa7f057b0c9f55a98ffb2c9754f02 (patch)
tree1a7a69e36ba10b559a1ac03491fc3db5f99c7efd /Assistant/DeleteRemote.hs
parent72b25b61e9c91668e0c05a17c50462b822885eb8 (diff)
check for unused keys on an unwanted remote, and move them off, before deleting it
Diffstat (limited to 'Assistant/DeleteRemote.hs')
-rw-r--r--Assistant/DeleteRemote.hs33
1 files changed, 31 insertions, 2 deletions
diff --git a/Assistant/DeleteRemote.hs b/Assistant/DeleteRemote.hs
index a23eeaa8e..25dd7720f 100644
--- a/Assistant/DeleteRemote.hs
+++ b/Assistant/DeleteRemote.hs
@@ -14,6 +14,9 @@ import Assistant.Common
import Assistant.WebApp.Types
import Assistant.WebApp
#endif
+import Assistant.TransferQueue
+import Logs.Transfer
+import Logs.Location
import Assistant.Alert
import Assistant.DaemonStatus
import Assistant.Types.UrlRenderer
@@ -21,6 +24,7 @@ import qualified Remote
import Remote.List
import qualified Git.Command
import Logs.Trust
+import qualified Annex
import qualified Data.Text as T
@@ -40,8 +44,33 @@ removeRemote uuid = do
updateSyncRemotes
return remote
-{- Called when a remote was marked as unwanted, and is now empty, so can be
- - removed. -}
+{- Called when a Remote is probably empty, to remove it.
+ -
+ - This does one last check for any objects remaining in the Remote,
+ - and if there are any, queues Downloads of them, and defers removing
+ - the remote for later. This is to catch any objects not referred to
+ - in keys in the current branch.
+ -}
+removableRemote :: UrlRenderer -> UUID -> Assistant ()
+removableRemote urlrenderer uuid = do
+ keys <- getkeys
+ if null keys
+ then finishRemovingRemote urlrenderer uuid
+ else do
+ r <- fromMaybe (error "unknown remote")
+ <$> liftAnnex (Remote.remoteFromUUID uuid)
+ mapM_ (queueremaining r) keys
+ where
+ queueremaining r k =
+ queueTransferWhenSmall "remaining object in unwanted remote"
+ Nothing (Transfer Download uuid k) r
+ {- Scanning for keys can take a long time; do not tie up
+ - the Annex monad while doing it, so other threads continue to
+ - run. -}
+ getkeys = do
+ a <- liftAnnex $ Annex.withCurrentState $ loggedKeysFor uuid
+ liftIO a
+
finishRemovingRemote :: UrlRenderer -> UUID -> Assistant ()
finishRemovingRemote urlrenderer uuid = do
void $ removeRemote uuid