summaryrefslogtreecommitdiff
path: root/Assistant/DeleteRemote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-04-03 17:01:40 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-04-03 17:01:40 -0400
commitf768f16999d997077be98c0d8eabd3d85fd8caa5 (patch)
tree40ff7020f523d3eb67f344a983af4a6d7c0aca26 /Assistant/DeleteRemote.hs
parent6543d5406c64bb00a58e74305ec9ca09a49faf0b (diff)
detect when unwanted remote is empty and remove it
Needs fixes to build when the webapp is disabled.
Diffstat (limited to 'Assistant/DeleteRemote.hs')
-rw-r--r--Assistant/DeleteRemote.hs52
1 files changed, 52 insertions, 0 deletions
diff --git a/Assistant/DeleteRemote.hs b/Assistant/DeleteRemote.hs
new file mode 100644
index 000000000..59aff57fe
--- /dev/null
+++ b/Assistant/DeleteRemote.hs
@@ -0,0 +1,52 @@
+{- git-annex assistant remote deletion utilities
+ -
+ - Copyright 2012 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Assistant.DeleteRemote where
+
+import Assistant.Common
+import Assistant.WebApp
+import Assistant.WebApp.Types
+import Assistant.Alert
+import Assistant.DaemonStatus
+import qualified Remote
+import Remote.List
+import qualified Git.Command
+import Logs.Trust
+
+import qualified Data.Text as T
+
+{- Removes a remote (but leave the repository as-is), and returns the old
+ - Remote data. -}
+removeRemote :: UUID -> Assistant Remote
+removeRemote uuid = do
+ remote <- fromMaybe (error "unknown remote")
+ <$> liftAnnex (Remote.remoteFromUUID uuid)
+ liftAnnex $ do
+ inRepo $ Git.Command.run
+ [ Param "remote"
+ , Param "remove"
+ , Param (Remote.name remote)
+ ]
+ void $ remoteListRefresh
+ updateSyncRemotes
+ return remote
+
+{- Called when a remote was marked as unwanted, and is now empty, so can be
+ - removed. -}
+finishRemovingRemote :: UrlRenderer -> UUID -> Assistant ()
+finishRemovingRemote urlrenderer uuid = do
+ void $ removeRemote uuid
+ liftAnnex $ trustSet uuid DeadTrusted
+
+ desc <- liftAnnex $ Remote.prettyUUID uuid
+ url <- liftIO $ renderUrl urlrenderer (FinishedDeletingRepositoryContentsR uuid) []
+ close <- asIO1 removeAlert
+ void $ addAlert $ remoteRemovalAlert desc $ AlertButton
+ { buttonLabel = T.pack "Finish removal"
+ , buttonUrl = url
+ , buttonAction = Just close
+ }