summaryrefslogtreecommitdiff
path: root/Assistant/DeleteRemote.hs
blob: a23eeaa8e9199b34e4996777d640d95b558be1f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{- git-annex assistant remote deletion utilities
 -
 - Copyright 2012 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

{-# LANGUAGE CPP #-}

module Assistant.DeleteRemote where

import Assistant.Common
#ifdef WITH_WEBAPP
import Assistant.WebApp.Types
import Assistant.WebApp
#endif
import Assistant.Alert
import Assistant.DaemonStatus
import Assistant.Types.UrlRenderer
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

#ifdef WITH_WEBAPP
	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
		}
#endif