summaryrefslogtreecommitdiff
path: root/Command/Whereis.hs
blob: fec41f410c296b76976a690d3ec2795c3950aa79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{- git-annex command
 -
 - Copyright 2010 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.Whereis where

import Annex.Common
import LocationLog
import Command
import Remote
import Trust

command :: [Command]
command = [repoCommand "whereis" paramPaths seek
	"lists repositories that have file content"]

seek :: [CommandSeek]
seek = [withFilesInGit start]

start :: FilePath -> CommandStart
start file = isAnnexed file $ \(key, _) -> do
	showStart "whereis" file
	next $ perform key

perform :: Key -> CommandPerform
perform key = do
	(untrustedlocations, safelocations) <- trustPartition UnTrusted =<< keyLocations key
	let num = length safelocations
	showNote $ show num ++ " " ++ copiesplural num
	pp <- prettyPrintUUIDs "whereis" safelocations
	unless (null safelocations) $
		showLongNote pp
	pp' <- prettyPrintUUIDs "untrusted" untrustedlocations
	unless (null untrustedlocations) $
		showLongNote $ untrustedheader ++ pp'
	if null safelocations then stop else next $ return True
	where
		copiesplural 1 = "copy"
		copiesplural _ = "copies"
		untrustedheader = "The following untrusted locations may also have copies:\n"