summaryrefslogtreecommitdiff
path: root/Logs/Activity.hs
blob: 6f5bf0deb95b9f037dc8f471578fa32916f0eb88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{- 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 Data.Time.Clock.POSIX

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
	ts <- liftIO getPOSIXTime
	Annex.Branch.change activityLog $
		showLog show . changeLog ts uuid act . parseLog readish

lastActivities :: Maybe Activity -> Annex (Log Activity)
lastActivities wantact = parseLog onlywanted <$> Annex.Branch.get activityLog
  where
	onlywanted s = case readish s of
		Just a | wanted a -> Just a
		_ -> Nothing
	wanted a = maybe True (a ==) wantact