summaryrefslogtreecommitdiff
path: root/Annex/NumCopies.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-10-08 18:20:36 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-10-08 18:20:36 -0400
commit51b93b1606bac86ffc66d4cf3a457888a6800778 (patch)
tree5cf6de63e314d21ee60084eb72d183669f074150 /Annex/NumCopies.hs
parent69903541bcb21b71c6aeecfb1a617a2a243f70b5 (diff)
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.
Diffstat (limited to 'Annex/NumCopies.hs')
-rw-r--r--Annex/NumCopies.hs27
1 files changed, 15 insertions, 12 deletions
diff --git a/Annex/NumCopies.hs b/Annex/NumCopies.hs
index 636855401..750946570 100644
--- a/Annex/NumCopies.hs
+++ b/Annex/NumCopies.hs
@@ -77,7 +77,11 @@ getFileNumCopies' file = maybe getGlobalNumCopies (return . Just) =<< getattr
{- Checks if numcopies are satisfied for a file by running a comparison
- 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 file key vs = do
have <- trustExclude UnTrusted =<< Remote.keyLocations key
@@ -89,14 +93,14 @@ numCopiesCheck' file vs have = do
return $ length have `vs` needed
{- 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
:: String -- message to print when there are no known locations
-> Key
-> NumCopies
-> [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
-> Annex Bool
verifyEnoughCopies nolocmsg key need skip preverified tocheck =
@@ -113,15 +117,13 @@ verifyEnoughCopies nolocmsg key need skip preverified tocheck =
if verifiedEnoughCopies need stillhave
then return True
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
haskey <- Remote.hasKey r key
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
- Right False -> helper bad (u:missing) have rs
- where
- u = Remote.uuid r
+ Right False -> helper bad (Remote.uuid r:missing) have rs
{- Check whether enough verification has been done of copies to allow
- dropping content safely.
@@ -138,10 +140,11 @@ verifyEnoughCopies nolocmsg key need skip preverified tocheck =
verifiedEnoughCopies :: NumCopies -> [VerifiedCopy] -> Bool
verifiedEnoughCopies (NumCopies n) l
| n == 0 = True
- | otherwise = length l >= n && any islock l
- where
- islock (VerifiedCopyLock _) = True
- islock _ = False
+ | otherwise = length (deDupVerifiedCopies l) >= n && any isFullVerification l
+
+isFullVerification :: VerifiedCopy -> Bool
+isFullVerification (VerifiedCopyLock _) = True
+isFullVerification _ = False
notEnoughCopies :: Key -> NumCopies -> [VerifiedCopy] -> [UUID] -> [Remote] -> String -> Annex ()
notEnoughCopies key need have skip bad nolocmsg = do