make filename available to fsck messages

This commit is contained in:
Joey Hess 2011-01-26 20:37:46 -04:00
parent c30d38e108
commit e1d213d6e3
5 changed files with 20 additions and 17 deletions

View file

@ -118,8 +118,8 @@ hasKey key = do
(B.hasKey backend) key (B.hasKey backend) key
{- Checks a key's backend for problems. -} {- Checks a key's backend for problems. -}
fsckKey :: Backend Annex -> Key -> Maybe Int -> Annex Bool fsckKey :: Backend Annex -> Key -> Maybe FilePath -> Maybe Int -> Annex Bool
fsckKey backend key numcopies = (B.fsckKey backend) key numcopies fsckKey backend key file numcopies = (B.fsckKey backend) key file numcopies
{- Looks up the key and backend corresponding to an annexed file, {- Looks up the key and backend corresponding to an annexed file,
- by examining what the file symlinks to. -} - by examining what the file symlinks to. -}

View file

@ -166,14 +166,14 @@ getNumCopies Nothing = do
- The passed action is first run to allow backends deriving this one - The passed action is first run to allow backends deriving this one
- to do their own checks. - to do their own checks.
-} -}
checkKey :: (Key -> Annex Bool) -> Key -> Maybe Int -> Annex Bool checkKey :: (Key -> Annex Bool) -> Key -> Maybe FilePath -> Maybe Int -> Annex Bool
checkKey a key numcopies = do checkKey a key file numcopies = do
a_ok <- a key a_ok <- a key
copies_ok <- checkKeyNumCopies key numcopies copies_ok <- checkKeyNumCopies key file numcopies
return $ a_ok && copies_ok return $ a_ok && copies_ok
checkKeyNumCopies :: Key -> Maybe Int -> Annex Bool checkKeyNumCopies :: Key -> Maybe FilePath -> Maybe Int -> Annex Bool
checkKeyNumCopies key numcopies = do checkKeyNumCopies key file numcopies = do
needed <- getNumCopies numcopies needed <- getNumCopies numcopies
g <- Annex.gitRepo g <- Annex.gitRepo
locations <- liftIO $ keyLocations g key locations <- liftIO $ keyLocations g key
@ -184,10 +184,12 @@ checkKeyNumCopies key numcopies = do
if present < needed if present < needed
then do then do
ppuuids <- prettyPrintUUIDs untrustedlocations ppuuids <- prettyPrintUUIDs untrustedlocations
warning $ missingNote (show key) present needed ppuuids warning $ missingNote (filename file key) present needed ppuuids
return False return False
else return True else return True
where where
filename Nothing k = show k
filename (Just f) _ = f
missingNote :: String -> Int -> Int -> String -> String missingNote :: String -> Int -> Int -> String -> String
missingNote file 0 _ [] = missingNote file 0 _ [] =
@ -203,5 +205,5 @@ missingNote file present needed [] =
"\nBack it up with git-annex copy." "\nBack it up with git-annex copy."
missingNote file present needed untrusted = missingNote file present needed untrusted =
missingNote file present needed [] ++ missingNote file present needed [] ++
"\nThe following untrusted copies may also exist: " ++ "\nThe following untrusted locations may also have copies: " ++
"\n" ++ untrusted "\n" ++ untrusted

View file

@ -41,8 +41,8 @@ dummyStore _ _ = return False
dummyRemove :: Key -> Maybe a -> Annex Bool dummyRemove :: Key -> Maybe a -> Annex Bool
dummyRemove _ _ = return False dummyRemove _ _ = return False
dummyFsck :: Key -> Maybe a -> Annex Bool dummyFsck :: Key -> Maybe FilePath -> Maybe a -> Annex Bool
dummyFsck _ _ = return True dummyFsck _ _ _ = return True
dummyOk :: Key -> Annex Bool dummyOk :: Key -> Annex Bool
dummyOk _ = return True dummyOk _ = return True

View file

@ -31,9 +31,10 @@ data Backend a = Backend {
-- checks if a backend is storing the content of a key -- checks if a backend is storing the content of a key
hasKey :: Key -> a Bool, hasKey :: Key -> a Bool,
-- called during fsck to check a key -- called during fsck to check a key
-- (second parameter may be the number of copies that there should -- (second parameter may be the filename associated with it)
-- (third parameter may be the number of copies that there should
-- be of the key) -- be of the key)
fsckKey :: Key -> Maybe Int -> a Bool fsckKey :: Key -> Maybe FilePath -> Maybe Int -> a Bool
} }
instance Show (Backend a) where instance Show (Backend a) where

View file

@ -24,13 +24,13 @@ seek = [withAttrFilesInGit "annex.numcopies" start]
start :: CommandStartAttrFile start :: CommandStartAttrFile
start (file, attr) = isAnnexed file $ \(key, backend) -> do start (file, attr) = isAnnexed file $ \(key, backend) -> do
showStart "fsck" file showStart "fsck" file
return $ Just $ perform key backend numcopies return $ Just $ perform key file backend numcopies
where where
numcopies = readMaybe attr :: Maybe Int numcopies = readMaybe attr :: Maybe Int
perform :: Key -> Backend Annex -> Maybe Int -> CommandPerform perform :: Key -> FilePath -> Backend Annex -> Maybe Int -> CommandPerform
perform key backend numcopies = do perform key file backend numcopies = do
success <- Backend.fsckKey backend key numcopies success <- Backend.fsckKey backend key (Just file) numcopies
if success if success
then return $ Just $ return True then return $ Just $ return True
else return Nothing else return Nothing