try harder to verify until at least one VerifiedCopyLock is obtained

This avoids a failure where eg, we start with RecentlyVerifiedCopies
for all remotes, and so didn't do any active verification, which is
required.

Also, dedup the list of VerifiedCopies when checking if we have enough,
in case 2 copies of a UUID slip in.
This commit is contained in:
Joey Hess 2015-10-08 18:20:36 -04:00
parent b17f5da6c9
commit e4a33967a1
Failed to extract signature

View file

@ -77,7 +77,11 @@ getFileNumCopies' file = maybe getGlobalNumCopies (return . Just) =<< getattr
{- Checks if numcopies are satisfied for a file by running a comparison {- Checks if numcopies are satisfied for a file by running a comparison
- between the number of (not untrusted) copies that are - between the number of (not untrusted) copies that are
- belived to exist, and the configured value. -} - belived to exist, and the configured value.
-
- This is good enough for everything except dropping the file, which
- requires active verification of the copies.
-}
numCopiesCheck :: FilePath -> Key -> (Int -> Int -> v) -> Annex v numCopiesCheck :: FilePath -> Key -> (Int -> Int -> v) -> Annex v
numCopiesCheck file key vs = do numCopiesCheck file key vs = do
have <- trustExclude UnTrusted =<< Remote.keyLocations key have <- trustExclude UnTrusted =<< Remote.keyLocations key
@ -89,14 +93,14 @@ numCopiesCheck' file vs have = do
return $ length have `vs` needed return $ length have `vs` needed
{- Verifies that enough copies of a key exist amoung the listed remotes, {- Verifies that enough copies of a key exist amoung the listed remotes,
- priting an informative message if not. - printing an informative message if not.
-} -}
verifyEnoughCopies verifyEnoughCopies
:: String -- message to print when there are no known locations :: String -- message to print when there are no known locations
-> Key -> Key
-> NumCopies -> NumCopies
-> [UUID] -- repos to skip considering (generally untrusted remotes) -> [UUID] -- repos to skip considering (generally untrusted remotes)
-> [VerifiedCopy] -- already known verifications -> [VerifiedCopy] -- copies already verified to exist
-> [Remote] -- remotes to check to see if they have it -> [Remote] -- remotes to check to see if they have it
-> Annex Bool -> Annex Bool
verifyEnoughCopies nolocmsg key need skip preverified tocheck = verifyEnoughCopies nolocmsg key need skip preverified tocheck =
@ -113,15 +117,13 @@ verifyEnoughCopies nolocmsg key need skip preverified tocheck =
if verifiedEnoughCopies need stillhave if verifiedEnoughCopies need stillhave
then return True then return True
else helper bad missing stillhave (r:rs) else helper bad missing stillhave (r:rs)
| any (== u) (map toUUID have) = helper bad missing have rs | any isFullVerification have = helper bad missing have rs
| otherwise = do | otherwise = do
haskey <- Remote.hasKey r key haskey <- Remote.hasKey r key
case haskey of case haskey of
Right True -> helper bad missing (mkVerifiedCopy RecentlyVerifiedCopy u : have) rs Right True -> helper bad missing (mkVerifiedCopy RecentlyVerifiedCopy r : have) rs
Left _ -> helper (r:bad) missing have rs Left _ -> helper (r:bad) missing have rs
Right False -> helper bad (u:missing) have rs Right False -> helper bad (Remote.uuid r:missing) have rs
where
u = Remote.uuid r
{- Check whether enough verification has been done of copies to allow {- Check whether enough verification has been done of copies to allow
- dropping content safely. - dropping content safely.
@ -138,10 +140,11 @@ verifyEnoughCopies nolocmsg key need skip preverified tocheck =
verifiedEnoughCopies :: NumCopies -> [VerifiedCopy] -> Bool verifiedEnoughCopies :: NumCopies -> [VerifiedCopy] -> Bool
verifiedEnoughCopies (NumCopies n) l verifiedEnoughCopies (NumCopies n) l
| n == 0 = True | n == 0 = True
| otherwise = length l >= n && any islock l | otherwise = length (deDupVerifiedCopies l) >= n && any isFullVerification l
where
islock (VerifiedCopyLock _) = True isFullVerification :: VerifiedCopy -> Bool
islock _ = False isFullVerification (VerifiedCopyLock _) = True
isFullVerification _ = False
notEnoughCopies :: Key -> NumCopies -> [VerifiedCopy] -> [UUID] -> [Remote] -> String -> Annex () notEnoughCopies :: Key -> NumCopies -> [VerifiedCopy] -> [UUID] -> [Remote] -> String -> Annex ()
notEnoughCopies key need have skip bad nolocmsg = do notEnoughCopies key need have skip bad nolocmsg = do