2013-10-22 20:02:52 +00:00
|
|
|
{- git-annex fsck results log files
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-10-22 20:02:52 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-10-22 20:02:52 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Logs.FsckResults (
|
|
|
|
writeFsckResults,
|
2013-11-30 18:29:11 +00:00
|
|
|
readFsckResults,
|
|
|
|
clearFsckResults,
|
2013-10-22 20:02:52 +00:00
|
|
|
) where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2013-10-22 20:02:52 +00:00
|
|
|
import Git.Fsck
|
|
|
|
import Git.Types
|
2018-01-02 21:17:10 +00:00
|
|
|
import Logs.File
|
2013-10-22 20:02:52 +00:00
|
|
|
|
|
|
|
import qualified Data.Set as S
|
|
|
|
|
|
|
|
writeFsckResults :: UUID -> FsckResults -> Annex ()
|
|
|
|
writeFsckResults u fsckresults = do
|
|
|
|
logfile <- fromRepo $ gitAnnexFsckResultsLog u
|
2018-01-02 21:17:10 +00:00
|
|
|
case fsckresults of
|
|
|
|
FsckFailed -> store S.empty False logfile
|
|
|
|
FsckFoundMissing s t
|
|
|
|
| S.null s -> liftIO $ nukeFile logfile
|
|
|
|
| otherwise -> store s t logfile
|
2013-10-22 20:02:52 +00:00
|
|
|
where
|
2018-01-02 21:17:10 +00:00
|
|
|
store s t logfile = writeLogFile logfile $ serialize s t
|
2014-03-12 19:18:43 +00:00
|
|
|
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
|
|
|
|
|