2013-10-22 20:02:52 +00:00
|
|
|
{- git-annex fsck results log files
|
|
|
|
-
|
|
|
|
- Copyright 2013 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Logs.FsckResults (
|
|
|
|
writeFsckResults,
|
2013-11-30 18:29:11 +00:00
|
|
|
readFsckResults,
|
|
|
|
clearFsckResults,
|
2013-10-22 20:02:52 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Utility.Tmp
|
|
|
|
import Git.Fsck
|
|
|
|
import Git.Types
|
|
|
|
|
|
|
|
import qualified Data.Set as S
|
|
|
|
|
|
|
|
writeFsckResults :: UUID -> FsckResults -> Annex ()
|
|
|
|
writeFsckResults u fsckresults = do
|
|
|
|
logfile <- fromRepo $ gitAnnexFsckResultsLog u
|
|
|
|
liftIO $
|
|
|
|
case fsckresults of
|
2013-11-30 18:29:11 +00:00
|
|
|
FsckFailed -> store S.empty logfile
|
|
|
|
FsckFoundMissing s
|
2013-10-22 20:02:52 +00:00
|
|
|
| S.null s -> nukeFile logfile
|
|
|
|
| otherwise -> store s logfile
|
|
|
|
where
|
|
|
|
store s logfile = do
|
|
|
|
createDirectoryIfMissing True (parentDir logfile)
|
|
|
|
liftIO $ viaTmp writeFile logfile $ serialize s
|
|
|
|
serialize = unlines . map show . S.toList
|
|
|
|
|
|
|
|
readFsckResults :: UUID -> Annex FsckResults
|
|
|
|
readFsckResults u = do
|
|
|
|
logfile <- fromRepo $ gitAnnexFsckResultsLog u
|
2013-11-30 18:29:11 +00:00
|
|
|
liftIO $ catchDefaultIO (FsckFoundMissing S.empty) $
|
2013-10-22 20:02:52 +00:00
|
|
|
deserialize <$> readFile logfile
|
|
|
|
where
|
|
|
|
deserialize l =
|
|
|
|
let s = S.fromList $ map Ref $ lines l
|
2013-11-30 18:29:11 +00:00
|
|
|
in if S.null s then FsckFailed else FsckFoundMissing s
|
|
|
|
|
|
|
|
clearFsckResults :: UUID -> Annex ()
|
|
|
|
clearFsckResults = liftIO . nukeFile <=< fromRepo . gitAnnexFsckResultsLog
|
|
|
|
|