writeFsckResults :: UUID -> FsckResults -> Annex ()
writeFsckResults u fsckresults = do
logfile <- fromRepo $ gitAnnexFsckResultsLog u
- case fsckresults of
- FsckFailed -> store S.empty False logfile
- FsckFoundMissing s t
- | S.null s -> liftIO $
- removeWhenExistsWith R.removeLink logfile
- | otherwise -> store s t logfile
+ case serializeFsckResults fsckresults of
+ Just s -> store s logfile
+ Nothing -> liftIO $
+ removeWhenExistsWith R.removeLink logfile
+ where
+ store s logfile = writeLogFile logfile s
+
+serializeFsckResults :: FsckResults -> Maybe String
+serializeFsckResults fsckresults = case fsckresults of
+ FsckFailed -> Just (serialize S.empty False)
+ FsckFoundMissing s t
+ | S.null s -> Nothing
+ | otherwise -> Just (serialize s t)
where
- store s t logfile = writeLogFile logfile $ serialize s t
serialize s t =
let ls = map fromRef (S.toList s)
in if t
readFsckResults u = do
logfile <- fromRepo $ gitAnnexFsckResultsLog u
liftIO $ catchDefaultIO (FsckFoundMissing S.empty False) $
- deserialize . lines <$> readFile (fromRawFilePath logfile)
+ deserializeFsckResults <$> readFile (fromRawFilePath logfile)
+
+deserializeFsckResults :: String -> FsckResults
+deserializeFsckResults = deserialize . lines
where
deserialize ("truncated":ls) = deserialize' ls True
deserialize ls = deserialize' ls False