support trusted repositories that are not configured as remotes

This commit is contained in:
Joey Hess 2010-12-29 16:58:44 -04:00
parent ef85e699ba
commit e64ffc212e
3 changed files with 20 additions and 15 deletions

View file

@ -49,7 +49,7 @@ dummyStore _ _ = return True
- and copy it over to this one. -} - and copy it over to this one. -}
copyKeyFile :: Key -> FilePath -> Annex Bool copyKeyFile :: Key -> FilePath -> Annex Bool
copyKeyFile key file = do copyKeyFile key file = do
(trusted, untrusted) <- Remotes.keyPossibilities key (trusted, untrusted, _) <- Remotes.keyPossibilities key
let remotes = trusted ++ untrusted let remotes = trusted ++ untrusted
if null remotes if null remotes
then do then do
@ -92,10 +92,9 @@ checkRemoveKey key numcopiesM = do
if force || numcopiesM == Just 0 if force || numcopiesM == Just 0
then return True then return True
else do else do
(trusted, untrusted) <- Remotes.keyPossibilities key (_, untrusted, have) <- Remotes.keyPossibilities key
numcopies <- getNumCopies numcopiesM numcopies <- getNumCopies numcopiesM
trusteduuids <- mapM getUUID trusted findcopies numcopies have untrusted []
findcopies numcopies trusteduuids untrusted []
where where
findcopies need have [] bad findcopies need have [] bad
| length have >= need = return True | length have >= need = return True

View file

@ -110,7 +110,7 @@ toCleanup move remote key tmpfile = do
fromStart :: Bool -> SubCmdStartString fromStart :: Bool -> SubCmdStartString
fromStart move file = isAnnexed file $ \(key, _) -> do fromStart move file = isAnnexed file $ \(key, _) -> do
remote <- Remotes.commandLineRemote remote <- Remotes.commandLineRemote
(trusted, untrusted) <- Remotes.keyPossibilities key (trusted, untrusted, _) <- Remotes.keyPossibilities key
if null $ filter (\r -> Remotes.same r remote) (trusted ++ untrusted) if null $ filter (\r -> Remotes.same r remote) (trusted ++ untrusted)
then return Nothing then return Nothing
else do else do

View file

@ -44,9 +44,15 @@ list :: [Git.Repo] -> String
list remotes = join ", " $ map Git.repoDescribe remotes list remotes = join ", " $ map Git.repoDescribe remotes
{- Cost ordered lists of remotes that the LocationLog indicate may have a key. {- Cost ordered lists of remotes that the LocationLog indicate may have a key.
- The first list is of remotes that are trusted to have the key; the -
- second is of untrusted remotes that may have the key. -} - The first list is of remotes that are trusted to have the key.
keyPossibilities :: Key -> Annex ([Git.Repo], [Git.Repo]) -
- The second is of untrusted remotes that may have the key.
-
- Also returns a list of all UUIDs that are trusted to have the key
- (some may not have configured remotes).
-}
keyPossibilities :: Key -> Annex ([Git.Repo], [Git.Repo], [UUID])
keyPossibilities key = do keyPossibilities key = do
allremotes <- remotesByCost allremotes <- remotesByCost
-- To determine if a remote has a key, its UUID needs to be known. -- To determine if a remote has a key, its UUID needs to be known.
@ -79,19 +85,19 @@ keyPossibilities key = do
cachedUUID r = do cachedUUID r = do
u <- getUUID r u <- getUUID r
return $ null u return $ null u
partition allremotes = do partition remotes = do
g <- Annex.gitRepo g <- Annex.gitRepo
validuuids <- liftIO $ keyLocations g key validuuids <- liftIO $ keyLocations g key
alltrusted <- getTrusted trusted <- getTrusted
-- get uuids trusted to have the key -- get uuids trusted to have the key
-- note that validuuids is assumed to not have dups -- note that validuuids is assumed to not have dups
let validtrusted = intersect validuuids alltrusted let validtrusteduuids = intersect validuuids trusted
-- remotes that match uuids that have the key -- remotes that match uuids that have the key
validremotes <- reposByUUID allremotes validuuids validremotes <- reposByUUID remotes validuuids
-- partition out the trusted and untrusted remotes -- partition out the trusted and untrusted remotes
trustedremotes <- reposByUUID validremotes validtrusted trustedremotes <- reposByUUID validremotes validtrusteduuids
untrustedremotes <- reposWithoutUUID validremotes alltrusted untrustedremotes <- reposWithoutUUID validremotes trusted
return (trustedremotes, untrustedremotes) return (trustedremotes, untrustedremotes, validtrusteduuids)
{- Checks if a given remote has the content for a key inAnnex. {- Checks if a given remote has the content for a key inAnnex.
- If the remote cannot be accessed, returns a Left error. - If the remote cannot be accessed, returns a Left error.