summaryrefslogtreecommitdiff
path: root/Command/Dead.hs
blob: 7e62b6db0b5404324501d9470ed47bf8043bb11d (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
{- git-annex command
 -
 - Copyright 2011, 2015 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.Dead where

import Command
import Common.Annex
import qualified Annex
import Types.TrustLevel
import Types.Key
import Command.Trust (trustCommand)
import Logs.Location
import Remote (keyLocations)

cmd :: [Command]
cmd = [withOptions [keyOption] $ 
	command "dead" (paramRepeating paramRemote) seek
		SectionSetup "hide a lost repository or key"]

seek :: CommandSeek
seek ps = maybe (trustCommand "dead" DeadTrusted ps) (flip seekKey ps)
	=<< Annex.getField "key"

seekKey :: String -> CommandSeek
seekKey ks = case file2key ks of
	Nothing -> error "Invalid key"
	Just key -> withNothing (startKey key)

startKey :: Key -> CommandStart
startKey key = do
	showStart "dead" (key2file key)
	ls <- keyLocations key
	case ls of
		[] -> next $ performKey key
		_ -> error "This key is still known to be present in some locations; not marking as dead."
		
performKey :: Key -> CommandPerform
performKey key = do
	setDead key
	next $ return True