2010-11-06 21:06:19 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Fsck where
|
|
|
|
|
2011-03-28 20:19:20 +00:00
|
|
|
import Control.Monad (when)
|
2011-03-02 18:30:36 +00:00
|
|
|
import Control.Monad.State (liftIO)
|
|
|
|
|
2010-11-06 21:06:19 +00:00
|
|
|
import Command
|
2010-11-15 22:22:50 +00:00
|
|
|
import qualified Backend
|
2011-03-02 18:30:36 +00:00
|
|
|
import qualified Annex
|
|
|
|
import UUID
|
2010-11-15 22:22:50 +00:00
|
|
|
import Types
|
|
|
|
import Messages
|
2010-11-28 19:28:20 +00:00
|
|
|
import Utility
|
2011-03-02 18:30:36 +00:00
|
|
|
import Content
|
|
|
|
import LocationLog
|
2011-03-28 20:19:20 +00:00
|
|
|
import Locations
|
2010-11-06 21:06:19 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
2011-03-19 22:58:49 +00:00
|
|
|
command = [repoCommand "fsck" (paramOptional $ paramRepeating paramPath) seek
|
2010-12-30 19:06:26 +00:00
|
|
|
"check for problems"]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2011-01-14 03:36:58 +00:00
|
|
|
seek = [withAttrFilesInGit "annex.numcopies" start]
|
2010-11-15 22:22:50 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartAttrFile
|
2011-03-03 20:40:55 +00:00
|
|
|
start (file, attr) = notBareRepo $ isAnnexed file $ \(key, backend) -> do
|
2010-11-15 22:22:50 +00:00
|
|
|
showStart "fsck" file
|
2011-01-27 00:37:46 +00:00
|
|
|
return $ Just $ perform key file backend numcopies
|
2010-11-28 19:28:20 +00:00
|
|
|
where
|
|
|
|
numcopies = readMaybe attr :: Maybe Int
|
2010-11-15 22:22:50 +00:00
|
|
|
|
2011-01-27 00:37:46 +00:00
|
|
|
perform :: Key -> FilePath -> Backend Annex -> Maybe Int -> CommandPerform
|
|
|
|
perform key file backend numcopies = do
|
2011-03-02 18:30:36 +00:00
|
|
|
-- the location log is checked first, so that if it has bad data
|
|
|
|
-- that gets corrected
|
|
|
|
locationlogok <- verifyLocationLog key file
|
|
|
|
backendok <- Backend.fsckKey backend key (Just file) numcopies
|
|
|
|
if locationlogok && backendok
|
2010-11-15 22:22:50 +00:00
|
|
|
then return $ Just $ return True
|
|
|
|
else return Nothing
|
2011-03-02 18:30:36 +00:00
|
|
|
|
|
|
|
{- Checks that the location log reflects the current status of the key,
|
|
|
|
in this repository only. -}
|
|
|
|
verifyLocationLog :: Key -> FilePath -> Annex Bool
|
|
|
|
verifyLocationLog key file = do
|
2011-03-28 20:19:20 +00:00
|
|
|
g <- Annex.gitRepo
|
2011-03-02 18:30:36 +00:00
|
|
|
present <- inAnnex key
|
|
|
|
|
2011-03-28 20:19:20 +00:00
|
|
|
-- Since we're checking that a key's file is present, throw
|
|
|
|
-- in a permission fixup here too.
|
|
|
|
when present $ liftIO $ do
|
|
|
|
let f = gitAnnexLocation g key
|
|
|
|
preventWrite f
|
|
|
|
preventWrite (parentDir f)
|
|
|
|
|
2011-03-02 18:30:36 +00:00
|
|
|
u <- getUUID g
|
|
|
|
uuids <- liftIO $ keyLocations g key
|
|
|
|
|
|
|
|
case (present, u `elem` uuids) of
|
|
|
|
(True, False) -> do
|
|
|
|
fix g u ValuePresent
|
|
|
|
-- There is no data loss, so do not fail.
|
|
|
|
return True
|
|
|
|
(False, True) -> do
|
|
|
|
fix g u ValueMissing
|
|
|
|
warning $
|
|
|
|
"** Based on the location log, " ++ file
|
|
|
|
++ "\n** was expected to be present, " ++
|
|
|
|
"but its content is missing."
|
|
|
|
return False
|
|
|
|
_ -> return True
|
|
|
|
|
|
|
|
where
|
|
|
|
fix g u s = do
|
|
|
|
showNote "fixing location log"
|
|
|
|
_ <- liftIO $ logChange g key u s
|
|
|
|
return ()
|