summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-10-29 16:45:06 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-10-29 16:45:06 -0400
commitfef2cf739872b905bbdf493f9f3ba7124400c633 (patch)
treedc9eb8ee2eec4e80e407bf7a1f233e0a0e1096a7
parent36f63ab19e54f51561dd9f2946c68037a8e99791 (diff)
refactor
-rw-r--r--Command/Fsck.hs36
1 files changed, 14 insertions, 22 deletions
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index 5d2e2ee50..9f3ae0263 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -1,6 +1,6 @@
{- git-annex command
-
- - Copyright 2010 Joey Hess <joey@kitenet.net>
+ - Copyright 2010,2011 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -32,14 +32,17 @@ start file numcopies = notBareRepo $ isAnnexed file $ \(key, backend) -> do
next $ perform key file backend numcopies
perform :: Key -> FilePath -> Backend Annex -> Maybe Int -> CommandPerform
-perform key file backend numcopies = do
- -- the location log is checked first, so that if it has bad data
- -- that gets corrected
- locationlogok <- verifyLocationLog key file
- backendok <- fsckKey backend key (Just file) numcopies
- if locationlogok && backendok
- then next $ return True
- else stop
+perform key file backend numcopies = check =<< sequence
+ -- order matters
+ [ verifyLocationLog key file
+ , checkKeySize key
+ , checkKeyNumCopies key file numcopies
+ , (Types.Backend.fsckKey backend) key
+ ]
+ where
+ check vs
+ | all (== True) vs = next $ return True
+ | otherwise = stop
{- Checks that the location log reflects the current status of the key,
in this repository only. -}
@@ -77,14 +80,6 @@ verifyLocationLog key file = do
showNote "fixing location log"
logChange g key u s
-{- Checks a key for problems. -}
-fsckKey :: Backend Annex -> Key -> Maybe FilePath -> Maybe Int -> Annex Bool
-fsckKey backend key file numcopies = do
- size_ok <- checkKeySize key
- copies_ok <- checkKeyNumCopies key file numcopies
- backend_ok <- (Types.Backend.fsckKey backend) key
- return $ size_ok && copies_ok && backend_ok
-
{- The size of the data for a key is checked against the size encoded in
- the key's metadata, if available. -}
checkKeySize :: Key -> Annex Bool
@@ -108,7 +103,7 @@ checkKeySize key = do
return False
-checkKeyNumCopies :: Key -> Maybe FilePath -> Maybe Int -> Annex Bool
+checkKeyNumCopies :: Key -> FilePath -> Maybe Int -> Annex Bool
checkKeyNumCopies key file numcopies = do
needed <- getNumCopies numcopies
(untrustedlocations, safelocations) <- trustPartition UnTrusted =<< keyLocations key
@@ -116,12 +111,9 @@ checkKeyNumCopies key file numcopies = do
if present < needed
then do
ppuuids <- Remote.prettyPrintUUIDs "untrusted" untrustedlocations
- warning $ missingNote (filename file key) present needed ppuuids
+ warning $ missingNote file present needed ppuuids
return False
else return True
- where
- filename Nothing k = show k
- filename (Just f) _ = f
missingNote :: String -> Int -> Int -> String -> String
missingNote file 0 _ [] =