2011-12-02 23:22:43 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-06-09 18:52:05 +00:00
|
|
|
- Copyright 2011, 2015 Joey Hess <id@joeyh.name>
|
2011-12-02 23:22:43 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Dead where
|
|
|
|
|
|
|
|
import Command
|
2015-06-09 18:52:05 +00:00
|
|
|
import Common.Annex
|
|
|
|
import qualified Annex
|
2014-02-20 19:12:35 +00:00
|
|
|
import Types.TrustLevel
|
2015-06-09 18:52:05 +00:00
|
|
|
import Types.Key
|
2014-02-20 19:12:35 +00:00
|
|
|
import Command.Trust (trustCommand)
|
2015-06-09 18:52:05 +00:00
|
|
|
import Logs.Location
|
|
|
|
import Remote (keyLocations)
|
2011-12-02 23:22:43 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
|
|
|
cmd = withOptions [keyOption] $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "dead" SectionSetup "hide a lost repository or key"
|
|
|
|
(paramRepeating paramRemote) (withParams seek)
|
2011-12-02 23:22:43 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2015-06-09 18:52:05 +00:00
|
|
|
seek ps = maybe (trustCommand "dead" DeadTrusted ps) (flip seekKey ps)
|
|
|
|
=<< Annex.getField "key"
|
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seekKey :: String -> CmdParams -> CommandSeek
|
2015-06-09 18:52:05 +00:00
|
|
|
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
|