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
|
2014-03-12 19:18:43 +00:00
|
|
|
FsckFailed -> store S.empty False logfile
|
|
|
|
FsckFoundMissing s t
|
2013-10-22 20:02:52 +00:00
|
|
|
| S.null s -> nukeFile logfile
|
2014-03-12 19:18:43 +00:00
|
|
|
| otherwise -> store s t logfile
|
2013-10-22 20:02:52 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
store s t logfile = do
|
2013-10-22 20:02:52 +00:00
|
|
|
createDirectoryIfMissing True (parentDir logfile)
|
2014-03-12 19:18:43 +00:00
|
|
|
liftIO $ viaTmp writeFile logfile $ serialize s t
|
|
|
|
serialize s t =
|
|
|
|
let ls = map fromRef (S.toList s)
|
|
|
|
in if t
|
|
|
|
then unlines ("truncated":ls)
|
|
|
|
else unlines ls
|
2013-10-22 20:02:52 +00:00
|
|
|
|
|
|
|
readFsckResults :: UUID -> Annex FsckResults
|
|
|
|
readFsckResults u = do
|
|
|
|
logfile <- fromRepo $ gitAnnexFsckResultsLog u
|
2014-03-12 19:18:43 +00:00
|
|
|
liftIO $ catchDefaultIO (FsckFoundMissing S.empty False) $
|
|
|
|
deserialize . lines <$> readFile logfile
|
2013-10-22 20:02:52 +00:00
|
|
|
where
|
2014-03-12 19:18:43 +00:00
|
|
|
deserialize ("truncated":ls) = deserialize' ls True
|
|
|
|
deserialize ls = deserialize' ls False
|
|
|
|
deserialize' ls t =
|
|
|
|
let s = S.fromList $ map Ref ls
|
|
|
|
in if S.null s then FsckFailed else FsckFoundMissing s t
|
2013-11-30 18:29:11 +00:00
|
|
|
|
|
|
|
clearFsckResults :: UUID -> Annex ()
|
|
|
|
clearFsckResults = liftIO . nukeFile <=< fromRepo . gitAnnexFsckResultsLog
|
|
|
|
|