blob: 8f4c8b93ad319e7c9e581c044c435ef48e459ba1 (
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
38
39
40
41
42
43
|
{- git-annex scheduled activities log
-
- Copyright 2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Logs.Schedule (
scheduleLog,
scheduleSet,
scheduleGet,
scheduleMap,
) where
import qualified Data.Map as M
import Data.Time.Clock.POSIX
import Common.Annex
import Types.ScheduledActivity
import qualified Annex.Branch
import Logs
import Logs.UUIDBased
scheduleSet :: UUID -> [ScheduledActivity] -> Annex ()
scheduleSet uuid@(UUID _) activities = do
ts <- liftIO getPOSIXTime
Annex.Branch.change scheduleLog $
showLog id . changeLog ts uuid val . parseLog Just
where
val = intercalate "; " $ map fromScheduledActivity activities
scheduleSet NoUUID _ = error "unknown UUID; cannot modify"
scheduleMap :: Annex (M.Map UUID [ScheduledActivity])
scheduleMap = simpleMap
. parseLogWithUUID parser
<$> Annex.Branch.get scheduleLog
where
parser _uuid = Just . mapMaybe toScheduledActivity . split "; "
scheduleGet :: UUID -> Annex [ScheduledActivity]
scheduleGet u = do
m <- scheduleMap
return $ fromMaybe [] $ M.lookup u m
|