summaryrefslogtreecommitdiff
path: root/Logs/FsckResults.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-10-22 16:02:52 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-10-22 16:02:52 -0400
commit3ca53d2779c695ebb6cbdd210fea2167562637ff (patch)
tree9fc7fe17043d36ec22b62039de7e2ef16bc2edb2 /Logs/FsckResults.hs
parentde5fdb11a238249c1b9b89a29277777a09f1cdb9 (diff)
add git fsck to cronner, and UI for repository repair (not yet wired up)
Diffstat (limited to 'Logs/FsckResults.hs')
-rw-r--r--Logs/FsckResults.hs43
1 files changed, 43 insertions, 0 deletions
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 <joey@kitenet.net>
+ -
+ - 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