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
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-12-02 23:22:43 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Dead where
|
|
|
|
|
|
|
|
import Command
|
2014-02-20 19:12:35 +00:00
|
|
|
import Types.TrustLevel
|
|
|
|
import Command.Trust (trustCommand)
|
2015-06-09 18:52:05 +00:00
|
|
|
import Logs.Location
|
|
|
|
import Remote (keyLocations)
|
2015-07-13 14:26:54 +00:00
|
|
|
import Git.Types
|
2011-12-02 23:22:43 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-13 14:26:54 +00:00
|
|
|
cmd = command "dead" SectionSetup "hide a lost repository or key"
|
|
|
|
(paramRepeating paramRemote) (seek <$$> optParser)
|
2011-12-02 23:22:43 +00:00
|
|
|
|
2015-07-13 14:26:54 +00:00
|
|
|
data DeadOptions = DeadRemotes [RemoteName] | DeadKeys [Key]
|
2015-06-09 18:52:05 +00:00
|
|
|
|
2015-07-13 14:26:54 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser DeadOptions
|
|
|
|
optParser desc = (DeadRemotes <$> cmdParams desc)
|
|
|
|
<|> (DeadKeys <$> many (option (str >>= parseKey)
|
|
|
|
( long "key" <> metavar paramKey
|
|
|
|
<> help "keys whose content has been irretrievably lost"
|
|
|
|
)))
|
|
|
|
|
|
|
|
seek :: DeadOptions -> CommandSeek
|
|
|
|
seek (DeadRemotes rs) = trustCommand "dead" DeadTrusted rs
|
2018-10-01 18:12:06 +00:00
|
|
|
seek (DeadKeys ks) = commandActions $ map startKey ks
|
2015-06-09 18:52:05 +00:00
|
|
|
|
|
|
|
startKey :: Key -> CommandStart
|
|
|
|
startKey key = do
|
2019-01-14 17:03:35 +00:00
|
|
|
showStart' "dead" (Just $ serializeKey key)
|
2017-12-05 19:00:50 +00:00
|
|
|
keyLocations key >>= \case
|
2015-06-09 18:52:05 +00:00
|
|
|
[] -> next $ performKey key
|
2016-11-16 01:29:54 +00:00
|
|
|
_ -> giveup "This key is still known to be present in some locations; not marking as dead."
|
2015-06-09 18:52:05 +00:00
|
|
|
|
|
|
|
performKey :: Key -> CommandPerform
|
|
|
|
performKey key = do
|
|
|
|
setDead key
|
|
|
|
next $ return True
|