blob: 7e76cadfe7eda033c873a37fd3fd9e1d3878025b (
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
|
{- git-annex scheduled activities
-
- Copyright 2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Types.ScheduledActivity where
import Common
import Utility.Scheduled
import Types.UUID
data ScheduledActivity
= ScheduledSelfFsck Schedule
| ScheduledRemoteFsck UUID Schedule
deriving (Eq, Show, Ord)
fromScheduledActivity :: ScheduledActivity -> String
fromScheduledActivity (ScheduledSelfFsck s) =
"fsck self " ++ fromSchedule s
fromScheduledActivity (ScheduledRemoteFsck u s) =
"fsck " ++ fromUUID u ++ fromSchedule s
toScheduledActivity :: String -> Maybe ScheduledActivity
toScheduledActivity = eitherToMaybe . parseScheduledActivity
parseScheduledActivity :: String -> Either String ScheduledActivity
parseScheduledActivity s = case words s of
("fsck":"self":rest) -> qualified $ ScheduledSelfFsck
<$> parseSchedule (unwords rest)
("fsck":u:rest) -> qualified $ ScheduledRemoteFsck
<$> pure (toUUID u)
<*> parseSchedule (unwords rest)
_ -> qualified $ Left "unknown activity"
where
qualified (Left e) = Left $ e ++ " in \"" ++ s ++ "\""
qualified v = v
|