summaryrefslogtreecommitdiff
path: root/Logs/UUIDBased.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-03 16:35:57 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-03 16:35:57 -0400
commit6e2eaff251cff32119f9def02afafa709e5d3da8 (patch)
treeef791fa88d0e8ea7dd3545cefe649034a6823683 /Logs/UUIDBased.hs
parent0013d5b66019a96c809d28c96a0d3555694b1de2 (diff)
add remote state logs
This allows a remote to store a piece of arbitrary state associated with a key. This is needed to support Tahoe, where the file-cap is calculated from the data stored in it, and used to retrieve a key later. Glacier also would be much improved by using this. GETSTATE and SETSTATE are added to the external special remote protocol. Note that the state is left as-is even when a key is removed from a remote. It's up to the remote to decide when it wants to clear the state. The remote state log, $KEY.log.rmt, is a UUID-based log. However, rather than using the old UUID-based log format, I created a new variant of that format. The new varient is more space efficient (since it lacks the "timestamp=" hack, and easier to parse (and the parser doesn't mess with whitespace in the value), and avoids compatability cruft in the old one. This seemed worth cleaning up for these new files, since there could be a lot of them, while before UUID-based logs were only used for a few log files at the top of the git-annex branch. The transition code has also been updated to handle these new UUID-based logs. This commit was sponsored by Daniel Hofer.
Diffstat (limited to 'Logs/UUIDBased.hs')
-rw-r--r--Logs/UUIDBased.hs25
1 files changed, 24 insertions, 1 deletions
diff --git a/Logs/UUIDBased.hs b/Logs/UUIDBased.hs
index 10b3bf55d..430c92d55 100644
--- a/Logs/UUIDBased.hs
+++ b/Logs/UUIDBased.hs
@@ -6,8 +6,10 @@
- A line of the log will look like: "UUID[ INFO[ timestamp=foo]]"
- The timestamp is last for backwards compatability reasons,
- and may not be present on old log lines.
+ -
+ - New uuid based logs instead use the form: "timestamp UUID INFO"
-
- - Copyright 2011 Joey Hess <joey@kitenet.net>
+ - Copyright 2011-2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -17,8 +19,10 @@ module Logs.UUIDBased (
LogEntry(..),
TimeStamp(..),
parseLog,
+ parseLogNew,
parseLogWithUUID,
showLog,
+ showLogNew,
changeLog,
addLog,
simpleMap,
@@ -56,6 +60,14 @@ showLog shower = unlines . map showpair . M.toList
showpair (k, LogEntry Unknown v) =
unwords [fromUUID k, shower v]
+showLogNew :: (a -> String) -> Log a -> String
+showLogNew shower = unlines . map showpair . M.toList
+ where
+ showpair (k, LogEntry (Date p) v) =
+ unwords [show p, fromUUID k, shower v]
+ showpair (k, LogEntry Unknown v) =
+ unwords ["0", fromUUID k, shower v]
+
parseLog :: (String -> Maybe a) -> String -> Log a
parseLog = parseLogWithUUID . const
@@ -86,6 +98,17 @@ parseLogWithUUID parser = M.fromListWith best . mapMaybe parse . lines
Nothing -> Unknown
Just d -> Date $ utcTimeToPOSIXSeconds d
+parseLogNew :: (String -> Maybe a) -> String -> Log a
+parseLogNew parser = M.fromListWith best . mapMaybe parse . lines
+ where
+ parse line = do
+ let (ts, rest) = splitword line
+ (u, v) = splitword rest
+ date <- Date . utcTimeToPOSIXSeconds <$> parseTime defaultTimeLocale "%s%Qs" ts
+ val <- parser v
+ Just (toUUID u, LogEntry date val)
+ splitword = separate (== ' ')
+
changeLog :: POSIXTime -> UUID -> a -> Log a -> Log a
changeLog t u v = M.insert u $ LogEntry (Date t) v