2015-04-09 19:34:47 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2015 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2015-04-09 19:34:47 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.ContentLocation where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Annex.Content
|
2019-12-11 18:12:22 +00:00
|
|
|
import qualified Utility.RawFilePath as R
|
|
|
|
|
|
|
|
import qualified Data.ByteString.Char8 as B8
|
2015-04-09 19:34:47 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2016-01-29 17:20:24 +00:00
|
|
|
cmd = noCommit $ noMessages $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "contentlocation" SectionPlumbing
|
|
|
|
"looks up content for a key"
|
2015-07-12 00:43:45 +00:00
|
|
|
(paramRepeating paramKey)
|
|
|
|
(batchable run (pure ()))
|
2015-04-09 19:34:47 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
run :: () -> SeekInput -> String -> Annex Bool
|
|
|
|
run _ _ p = do
|
2019-01-14 17:17:47 +00:00
|
|
|
let k = fromMaybe (giveup "bad key") $ deserializeKey p
|
2019-12-11 18:12:22 +00:00
|
|
|
maybe (return False) (\f -> liftIO (B8.putStrLn f) >> return True)
|
2015-04-09 19:34:47 +00:00
|
|
|
=<< inAnnex' (pure True) Nothing check k
|
|
|
|
where
|
2019-12-11 18:12:22 +00:00
|
|
|
check f = ifM (liftIO (R.doesPathExist f))
|
2015-04-09 19:34:47 +00:00
|
|
|
( return (Just f)
|
|
|
|
, return Nothing
|
|
|
|
)
|