summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-03-20 11:44:46 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-03-20 11:44:46 -0400
commitf90490c4f36d9354e004985621e5ebd767e62496 (patch)
tree671b20435330564060b8e375697ce83669c5cc19
parent82ee689db44ebabca2ecd093f9da40ef46fbc067 (diff)
checkpresentkey: New plumbing command to check if a key can be verified to be present on a remote.
-rw-r--r--CmdLine/GitAnnex.hs2
-rw-r--r--Command/CheckPresentKey.hs36
-rw-r--r--debian/changelog2
-rw-r--r--doc/git-annex.mdwn9
4 files changed, 49 insertions, 0 deletions
diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs
index f2953da36..6dedd94f5 100644
--- a/CmdLine/GitAnnex.hs
+++ b/CmdLine/GitAnnex.hs
@@ -30,6 +30,7 @@ import qualified Command.TransferKey
import qualified Command.TransferKeys
import qualified Command.SetPresentKey
import qualified Command.ReadPresentKey
+import qualified Command.CheckPresentKey
import qualified Command.ReKey
import qualified Command.MetaData
import qualified Command.View
@@ -158,6 +159,7 @@ cmds = concat
, Command.TransferKeys.cmd
, Command.SetPresentKey.cmd
, Command.ReadPresentKey.cmd
+ , Command.CheckPresentKey.cmd
, Command.ReKey.cmd
, Command.MetaData.cmd
, Command.View.cmd
diff --git a/Command/CheckPresentKey.hs b/Command/CheckPresentKey.hs
new file mode 100644
index 000000000..ad61ba3c0
--- /dev/null
+++ b/Command/CheckPresentKey.hs
@@ -0,0 +1,36 @@
+{- git-annex command
+ -
+ - Copyright 2015 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Command.CheckPresentKey where
+
+import Common.Annex
+import Command
+import Types.Key
+import qualified Remote
+import Annex
+import Types.Messages
+
+cmd :: [Command]
+cmd = [noCommit $ command "checkpresentkey" (paramPair paramKey paramRemote) seek
+ SectionPlumbing "check if key is present in remote"]
+
+seek :: CommandSeek
+seek = withWords start
+
+start :: [String] -> CommandStart
+start (ks:rn:[]) = do
+ setOutput QuietOutput
+ maybe (error "Unknown remote") (go <=< flip Remote.hasKey k)
+ =<< Remote.byNameWithUUID (Just rn)
+ where
+ k = fromMaybe (error "bad key") (file2key ks)
+ go (Right True) = liftIO exitSuccess
+ go (Right False) = liftIO exitFailure
+ go (Left e) = liftIO $ do
+ hPutStrLn stderr e
+ exitWith $ ExitFailure 100
+start _ = error "Wrong number of parameters"
diff --git a/debian/changelog b/debian/changelog
index d3c3b048a..0578cb2a5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
git-annex (5.20150318) UNRELEASED; urgency=medium
* readpresentkey: New plumbing command for checking location log.
+ * checkpresentkey: New plumbing command to check if a key can be verified
+ to be present on a remote.
-- Joey Hess <id@joeyh.name> Thu, 19 Mar 2015 17:05:32 -0400
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index c0bf08e0b..7cd02fb63 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -1010,6 +1010,15 @@ subdirectories).
It exits 0 if the key is recorded to be present and 1 if not.
+* `checkpresentkey key remote`
+
+ This plumbing-level command verifies if the specified key's content
+ is present in the specified remote.
+
+ Exits 0 if the content is verified present, or 1 if it is verified to not
+ be present. If there is a problem checking the remote, the special
+ exit code 100 is used, and an error message is output to stderr.
+
* `rekey [file key ...]`
This plumbing-level command is similar to migrate, but you specify