From 3ca53d2779c695ebb6cbdd210fea2167562637ff Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 22 Oct 2013 16:02:52 -0400 Subject: add git fsck to cronner, and UI for repository repair (not yet wired up) --- Logs/FsckResults.hs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Logs/FsckResults.hs (limited to 'Logs') diff --git a/Logs/FsckResults.hs b/Logs/FsckResults.hs new file mode 100644 index 000000000..75ed7389c --- /dev/null +++ b/Logs/FsckResults.hs @@ -0,0 +1,43 @@ +{- git-annex fsck results log files + - + - Copyright 2013 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Logs.FsckResults ( + writeFsckResults, + readFsckResults +) 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 + Nothing -> store S.empty logfile + Just s + | 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 + liftIO $ catchDefaultIO (Just S.empty) $ + deserialize <$> readFile logfile + where + deserialize l = + let s = S.fromList $ map Ref $ lines l + in if S.null s then Nothing else Just s -- cgit v1.2.3