summaryrefslogtreecommitdiff
path: root/Remotes.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-23 13:18:47 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-23 13:18:47 -0400
commit9dfbf40d1a8493ec191f8e79410ed9d2a9508141 (patch)
treef740095602d3f7733bdc3cccf598f699fdc2815f /Remotes.hs
parent5a91543be33719d6da7b53c4c449be8f75481375 (diff)
reorg remote key presense checking code
Also, it now checks if a key is inAnnex, ie, cached in .git/annex, not if it is present in a remote. For the File Backend, these are equivilant, not so for other backends.
Diffstat (limited to 'Remotes.hs')
-rw-r--r--Remotes.hs31
1 files changed, 24 insertions, 7 deletions
diff --git a/Remotes.hs b/Remotes.hs
index f24da2c22..13f66aae2 100644
--- a/Remotes.hs
+++ b/Remotes.hs
@@ -2,8 +2,9 @@
module Remotes (
list,
- withKey,
- tryGitConfigRead
+ keyPossibilities,
+ tryGitConfigRead,
+ inAnnex
) where
import Control.Exception
@@ -18,18 +19,19 @@ import Maybe
import Types
import qualified GitRepo as Git
import qualified Annex
+import qualified Backend
import LocationLog
import Locations
import UUID
-import Core
+import qualified Core
{- Human visible list of remotes. -}
list :: [Git.Repo] -> String
list remotes = join ", " $ map Git.repoDescribe remotes
{- Cost ordered list of remotes that the LocationLog indicate may have a key. -}
-withKey :: Key -> Annex [Git.Repo]
-withKey key = do
+keyPossibilities :: Key -> Annex [Git.Repo]
+keyPossibilities key = do
g <- Annex.gitRepo
uuids <- liftIO $ keyLocations g key
allremotes <- remotesByCost
@@ -50,20 +52,35 @@ withKey key = do
let expensive = filter Git.repoIsUrl allremotes
doexpensive <- filterM cachedUUID expensive
if (not $ null doexpensive)
- then showNote $ "getting UUIDs for " ++ (list doexpensive) ++ "..."
+ then Core.showNote $ "getting UUIDs for " ++ (list doexpensive) ++ "..."
else return ()
let todo = cheap ++ doexpensive
if (not $ null todo)
then do
e <- mapM tryGitConfigRead todo
Annex.flagChange "remotesread" $ FlagBool True
- withKey key
+ keyPossibilities key
else reposByUUID allremotes uuids
where
cachedUUID r = do
u <- getUUID r
return $ null u
+{- Checks if a given remote has the content for a key inAnnex.
+ -
+ - This is done by constructing a new Annex monad using the remote.
+ -
+ - If the remote cannot be accessed, returns a Left error.
+ -}
+inAnnex :: Git.Repo -> Key -> Annex (Either IOException Bool)
+inAnnex remote key = do
+ a <- liftIO $ Annex.new remote []
+ liftIO $ ((try $ check a)::IO (Either IOException Bool))
+ where
+ check a = do
+ (result, _) <- Annex.run a (Core.inAnnex key)
+ return result
+
{- Cost Ordered list of remotes. -}
remotesByCost :: Annex [Git.Repo]
remotesByCost = do