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
|
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
|
|
|
|
seek (DeadKeys ks) = seekActions $ pure $ map startKey ks
|
2015-06-09 18:52:05 +00:00
|
|
|
|
|
|
|
startKey :: Key -> CommandStart
|
|
|
|
startKey key = do
|
|
|
|
showStart "dead" (key2file key)
|
|
|
|
ls <- keyLocations key
|
|
|
|
case ls of
|
|
|
|
[] -> 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
|