git-annex/Logs/Activity.hs
Joey Hess bfc9039ead
convert git-annex branch access to ByteStrings and Builders
Most of the individual logs are not converted yet, only presense logs
have an efficient ByteString Builder implemented so far. The rest
convert to and from String.
2019-01-03 13:21:48 -04:00

35 lines
862 B
Haskell

{- git-annex activity log
-
- Copyright 2015 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Logs.Activity (
Log,
Activity(..),
recordActivity,
lastActivities,
) where
import Annex.Common
import qualified Annex.Branch
import Logs
import Logs.UUIDBased
data Activity = Fsck
deriving (Eq, Read, Show, Enum, Bounded)
recordActivity :: Activity -> UUID -> Annex ()
recordActivity act uuid = do
c <- liftIO currentVectorClock
Annex.Branch.change activityLog $
encodeBL . showLog show . changeLog c uuid act . parseLog readish . decodeBL
lastActivities :: Maybe Activity -> Annex (Log Activity)
lastActivities wantact = parseLog onlywanted . decodeBL <$> Annex.Branch.get activityLog
where
onlywanted s = case readish s of
Just a | wanted a -> Just a
_ -> Nothing
wanted a = maybe True (a ==) wantact