2011-12-02 19:22:43 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-06-09 14:52:05 -04:00
|
|
|
- Copyright 2011, 2015 Joey Hess <id@joeyh.name>
|
2011-12-02 19:22:43 -04:00
|
|
|
-
|
2019-03-13 15:48:14 -04:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-12-02 19:22:43 -04:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Dead where
|
|
|
|
|
|
|
|
import Command
|
2014-02-20 15:12:35 -04:00
|
|
|
import Types.TrustLevel
|
|
|
|
import Command.Trust (trustCommand)
|
2015-06-09 14:52:05 -04:00
|
|
|
import Logs.Location
|
|
|
|
import Remote (keyLocations)
|
2015-07-13 10:26:54 -04:00
|
|
|
import Git.Types
|
2011-12-02 19:22:43 -04:00
|
|
|
|
2015-07-08 12:33:27 -04:00
|
|
|
cmd :: Command
|
2015-07-13 10:26:54 -04:00
|
|
|
cmd = command "dead" SectionSetup "hide a lost repository or key"
|
|
|
|
(paramRepeating paramRemote) (seek <$$> optParser)
|
2011-12-02 19:22:43 -04:00
|
|
|
|
2015-07-13 10:26:54 -04:00
|
|
|
data DeadOptions = DeadRemotes [RemoteName] | DeadKeys [Key]
|
2015-06-09 14:52:05 -04:00
|
|
|
|
2015-07-13 10:26:54 -04: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 14:12:06 -04:00
|
|
|
seek (DeadKeys ks) = commandActions $ map startKey ks
|
2015-06-09 14:52:05 -04:00
|
|
|
|
|
|
|
startKey :: Key -> CommandStart
|
|
|
|
startKey key = do
|
2019-01-14 13:03:35 -04:00
|
|
|
showStart' "dead" (Just $ serializeKey key)
|
2017-12-05 15:00:50 -04:00
|
|
|
keyLocations key >>= \case
|
2015-06-09 14:52:05 -04:00
|
|
|
[] -> next $ performKey key
|
2016-11-15 21:29:54 -04:00
|
|
|
_ -> giveup "This key is still known to be present in some locations; not marking as dead."
|
2015-06-09 14:52:05 -04:00
|
|
|
|
|
|
|
performKey :: Key -> CommandPerform
|
|
|
|
performKey key = do
|
|
|
|
setDead key
|
|
|
|
next $ return True
|