2013-12-15 18:02:23 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2017-12-08 19:35:02 +00:00
|
|
|
- Copyright 2013-2017 Joey Hess <id@joeyh.name>
|
2013-12-15 18:02:23 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-12-15 18:02:23 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.LookupKey where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Annex.CatFile
|
2017-12-08 19:35:02 +00:00
|
|
|
import qualified Git.LsFiles
|
2013-12-15 18:02:23 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2016-01-29 17:20:24 +00:00
|
|
|
cmd = notBareRepo $ noCommit $ noMessages $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "lookupkey" SectionPlumbing
|
|
|
|
"looks up key used for file"
|
2015-07-12 00:43:45 +00:00
|
|
|
(paramRepeating paramFile)
|
|
|
|
(batchable run (pure ()))
|
2013-12-15 18:02:23 +00:00
|
|
|
|
2015-07-12 00:43:45 +00:00
|
|
|
run :: () -> String -> Annex Bool
|
2017-12-08 19:35:02 +00:00
|
|
|
run _ file = seekSingleGitFile file >>= \case
|
|
|
|
Nothing -> return False
|
|
|
|
Just file' -> catKeyFile file' >>= \case
|
2015-07-12 00:43:45 +00:00
|
|
|
Just k -> do
|
2019-01-14 17:03:35 +00:00
|
|
|
liftIO $ putStrLn $ serializeKey k
|
2015-07-12 00:43:45 +00:00
|
|
|
return True
|
|
|
|
Nothing -> return False
|
2017-12-08 19:35:02 +00:00
|
|
|
|
|
|
|
-- To support absolute filenames, pass through git ls-files.
|
|
|
|
-- But, this plumbing command does not recurse through directories.
|
2019-12-05 15:40:10 +00:00
|
|
|
seekSingleGitFile :: FilePath -> Annex (Maybe RawFilePath)
|
2017-12-08 19:35:02 +00:00
|
|
|
seekSingleGitFile file = do
|
2019-12-05 15:40:10 +00:00
|
|
|
(l, cleanup) <- inRepo (Git.LsFiles.inRepo [toRawFilePath file])
|
2017-12-08 19:35:02 +00:00
|
|
|
r <- case l of
|
2019-12-05 15:40:10 +00:00
|
|
|
(f:[]) | takeFileName (fromRawFilePath f) == takeFileName file ->
|
|
|
|
return (Just f)
|
2017-12-08 19:35:02 +00:00
|
|
|
_ -> return Nothing
|
|
|
|
void $ liftIO cleanup
|
|
|
|
return r
|