git-annex/Command/CalcKey.hs
Joey Hess d3ab5e626b
rename key2file and file2key
What these generate is not really suitable to be used as a filename,
which is why keyFile and fileKey further escape it. These are just
serializing Keys.

Also removed a quickcheck test that was very unlikely to test anything
useful, since it relied on random chance creating something that looks
like a serialized key. The other test is sufficient for testing what
that was intended to test anyway.
2019-01-14 13:03:35 -04:00

26 lines
640 B
Haskell

{- 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 = genKey (KeySource file file Nothing) Nothing >>= \case
Just (k, _) -> do
liftIO $ putStrLn $ serializeKey k
return True
Nothing -> return False