diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-03-20 11:44:46 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-03-20 11:44:46 -0400 |
commit | f90490c4f36d9354e004985621e5ebd767e62496 (patch) | |
tree | 671b20435330564060b8e375697ce83669c5cc19 /Command/CheckPresentKey.hs | |
parent | 82ee689db44ebabca2ecd093f9da40ef46fbc067 (diff) |
checkpresentkey: New plumbing command to check if a key can be verified to be present on a remote.
Diffstat (limited to 'Command/CheckPresentKey.hs')
-rw-r--r-- | Command/CheckPresentKey.hs | 36 |
1 files changed, 36 insertions, 0 deletions
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" |