2013-04-03 21:01:40 +00:00
|
|
|
{- git-annex assistant remote deletion utilities
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-04-03 21:44:34 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2013-04-03 21:01:40 +00:00
|
|
|
module Assistant.DeleteRemote where
|
|
|
|
|
|
|
|
import Assistant.Common
|
2013-04-04 05:48:26 +00:00
|
|
|
import Assistant.Types.UrlRenderer
|
2013-04-03 23:03:16 +00:00
|
|
|
import Assistant.TransferQueue
|
|
|
|
import Logs.Transfer
|
|
|
|
import Logs.Location
|
2013-04-03 21:01:40 +00:00
|
|
|
import Assistant.DaemonStatus
|
|
|
|
import qualified Remote
|
|
|
|
import Remote.List
|
2013-09-18 19:30:53 +00:00
|
|
|
import qualified Git.Remote
|
2013-04-03 21:01:40 +00:00
|
|
|
import Logs.Trust
|
2013-04-03 23:03:16 +00:00
|
|
|
import qualified Annex
|
2013-04-03 21:01:40 +00:00
|
|
|
|
2013-04-04 05:48:26 +00:00
|
|
|
#ifdef WITH_WEBAPP
|
|
|
|
import Assistant.WebApp.Types
|
|
|
|
import Assistant.Alert
|
2013-04-03 21:01:40 +00:00
|
|
|
import qualified Data.Text as T
|
2013-04-04 05:48:26 +00:00
|
|
|
#endif
|
2013-04-03 21:01:40 +00:00
|
|
|
|
|
|
|
{- Removes a remote (but leave the repository as-is), and returns the old
|
|
|
|
- Remote data. -}
|
2013-04-04 00:54:53 +00:00
|
|
|
disableRemote :: UUID -> Assistant Remote
|
|
|
|
disableRemote uuid = do
|
2013-04-03 21:01:40 +00:00
|
|
|
remote <- fromMaybe (error "unknown remote")
|
|
|
|
<$> liftAnnex (Remote.remoteFromUUID uuid)
|
|
|
|
liftAnnex $ do
|
2013-09-18 19:30:53 +00:00
|
|
|
inRepo $ Git.Remote.remove (Remote.name remote)
|
2013-04-03 21:01:40 +00:00
|
|
|
void $ remoteListRefresh
|
|
|
|
updateSyncRemotes
|
|
|
|
return remote
|
|
|
|
|
2013-04-04 00:54:53 +00:00
|
|
|
{- Removes a remote, marking it dead .-}
|
|
|
|
removeRemote :: UUID -> Assistant Remote
|
|
|
|
removeRemote uuid = do
|
|
|
|
liftAnnex $ trustSet uuid DeadTrusted
|
|
|
|
disableRemote uuid
|
|
|
|
|
2013-04-03 23:03:16 +00:00
|
|
|
{- 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
|
|
|
|
|
2013-04-04 00:54:53 +00:00
|
|
|
{- With the webapp, this asks the user to click on a button to finish
|
|
|
|
- removing the remote.
|
|
|
|
-
|
|
|
|
- Without the webapp, just do the removal now.
|
|
|
|
-}
|
2013-04-03 21:01:40 +00:00
|
|
|
finishRemovingRemote :: UrlRenderer -> UUID -> Assistant ()
|
2013-04-03 21:44:34 +00:00
|
|
|
#ifdef WITH_WEBAPP
|
2013-04-04 05:48:26 +00:00
|
|
|
finishRemovingRemote urlrenderer uuid = do
|
2013-04-03 21:01:40 +00:00
|
|
|
desc <- liftAnnex $ Remote.prettyUUID uuid
|
2013-04-04 05:48:26 +00:00
|
|
|
button <- mkAlertButton (T.pack "Finish deletion process") urlrenderer $
|
|
|
|
FinishDeleteRepositoryR uuid
|
|
|
|
void $ addAlert $ remoteRemovalAlert desc button
|
2013-04-04 00:54:53 +00:00
|
|
|
#else
|
2013-04-04 05:48:26 +00:00
|
|
|
finishRemovingRemote _ uuid = void $ removeRemote uuid
|
2013-04-03 21:44:34 +00:00
|
|
|
#endif
|