2011-03-05 21:23:55 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Whereis where
|
|
|
|
|
2012-02-14 07:49:48 +00:00
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2011-03-05 21:23:55 +00:00
|
|
|
import Command
|
2011-07-01 19:24:07 +00:00
|
|
|
import Remote
|
2011-10-15 20:21:08 +00:00
|
|
|
import Logs.Trust
|
2011-03-05 21:23:55 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
|
|
|
def = [command "whereis" paramPaths seek
|
2011-03-05 21:23:55 +00:00
|
|
|
"lists repositories that have file content"]
|
|
|
|
|
|
|
|
seek :: [CommandSeek]
|
2012-02-14 07:49:48 +00:00
|
|
|
seek = [withValue (remoteMap id) $ \m ->
|
|
|
|
withFilesInGit $ whenAnnexed $ start m]
|
2011-03-05 21:23:55 +00:00
|
|
|
|
2012-02-16 04:41:30 +00:00
|
|
|
start :: M.Map UUID Remote -> FilePath -> (Key, Backend) -> CommandStart
|
2012-02-14 07:49:48 +00:00
|
|
|
start remotemap file (key, _) = do
|
2011-03-05 21:23:55 +00:00
|
|
|
showStart "whereis" file
|
2012-02-14 07:49:48 +00:00
|
|
|
next $ perform remotemap key
|
2011-03-05 21:23:55 +00:00
|
|
|
|
2012-02-16 04:41:30 +00:00
|
|
|
perform :: M.Map UUID Remote -> Key -> CommandPerform
|
2012-02-14 07:49:48 +00:00
|
|
|
perform remotemap key = do
|
|
|
|
locations <- keyLocations key
|
|
|
|
(untrustedlocations, safelocations) <- trustPartition UnTrusted locations
|
2011-09-06 20:59:53 +00:00
|
|
|
let num = length safelocations
|
2011-03-05 21:41:36 +00:00
|
|
|
showNote $ show num ++ " " ++ copiesplural num
|
2011-09-06 20:59:53 +00:00
|
|
|
pp <- prettyPrintUUIDs "whereis" safelocations
|
2011-10-31 20:46:51 +00:00
|
|
|
unless (null safelocations) $ showLongNote pp
|
2011-09-06 20:59:53 +00:00
|
|
|
pp' <- prettyPrintUUIDs "untrusted" untrustedlocations
|
2011-10-31 20:46:51 +00:00
|
|
|
unless (null untrustedlocations) $ showLongNote $ untrustedheader ++ pp'
|
2012-02-14 07:49:48 +00:00
|
|
|
forM_ (catMaybes $ map (`M.lookup` remotemap) locations) $
|
|
|
|
performRemote key
|
2011-09-06 20:59:53 +00:00
|
|
|
if null safelocations then stop else next $ return True
|
2011-03-05 21:41:36 +00:00
|
|
|
where
|
|
|
|
copiesplural 1 = "copy"
|
|
|
|
copiesplural _ = "copies"
|
2011-09-06 20:59:53 +00:00
|
|
|
untrustedheader = "The following untrusted locations may also have copies:\n"
|
2012-02-14 07:49:48 +00:00
|
|
|
|
|
|
|
performRemote :: Key -> Remote -> Annex ()
|
|
|
|
performRemote key remote = case whereisKey remote of
|
|
|
|
Nothing -> return ()
|
|
|
|
Just a -> do
|
|
|
|
ls <- a key
|
|
|
|
unless (null ls) $ showLongNote $
|
|
|
|
unlines $ map (\l -> name remote ++ ": " ++ l) ls
|