calckey: New plumbing command, calculates the key that would be used to refer to a file

This commit is contained in:
Joey Hess 2016-04-20 13:49:42 -04:00
parent 9d952fe9d1
commit 1bfea9b3e5
Failed to extract signature
6 changed files with 104 additions and 0 deletions

28
Command/CalcKey.hs Normal file
View file

@ -0,0 +1,28 @@
{- git-annex command
-
- Copyright 2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.CalcKey where
import Command
import Backend (genKey)
import Types.KeySource
cmd :: Command
cmd = noCommit $ noMessages $ dontCheck repoExists $
command "calckey" SectionPlumbing
"calculates the key that would be used to refer to a file"
(paramRepeating paramFile)
(batchable run (pure ()))
run :: () -> String -> Annex Bool
run _ file = do
mkb <- genKey (KeySource file file Nothing) Nothing
case mkb of
Just (k, _) -> do
liftIO $ putStrLn $ key2file k
return True
Nothing -> return False