aboutsummaryrefslogtreecommitdiff
path: root/Command/Dead.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-06-09 14:52:05 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-06-09 14:52:05 -0400
commit47c2ad33d08bb828cd63544bc4c9cb1d294fc090 (patch)
tree2d04fc77302c1ab9f89fa55884e649876d685b8d /Command/Dead.hs
parentf80592f1603fdfdde4b092e9880646ded505163a (diff)
dead --key: Can be used to mark a key as dead.
Diffstat (limited to 'Command/Dead.hs')
-rw-r--r--Command/Dead.hs33
1 files changed, 29 insertions, 4 deletions
diff --git a/Command/Dead.hs b/Command/Dead.hs
index 464db25f9..7e62b6db0 100644
--- a/Command/Dead.hs
+++ b/Command/Dead.hs
@@ -1,6 +1,6 @@
{- git-annex command
-
- - Copyright 2011 Joey Hess <id@joeyh.name>
+ - Copyright 2011, 2015 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -8,12 +8,37 @@
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 = [command "dead" (paramRepeating paramRemote) seek
- SectionSetup "hide a lost repository"]
+cmd = [withOptions [keyOption] $
+ command "dead" (paramRepeating paramRemote) seek
+ SectionSetup "hide a lost repository or key"]
seek :: CommandSeek
-seek = trustCommand "dead" DeadTrusted
+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