summaryrefslogtreecommitdiff
path: root/Logs/Chunk
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-28 13:19:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-28 13:19:08 -0400
commitc25686d17f4b1c7850b8b733b5e63cb829becb3f (patch)
treef8aded3f06947a194a51d65659d6c02b470dafa8 /Logs/Chunk
parent188fbb1d937db0f63841dcc55cea9999e16aff52 (diff)
add ChunkMethod type and make Logs.Chunk use it, rather than assuming fixed size chunks (so eg, rolling hash chunks can be supported later)
If a newer git-annex starts logging something else in the chunk log, it won't be used by this version, but it will be preserved when updating the log.
Diffstat (limited to 'Logs/Chunk')
-rw-r--r--Logs/Chunk/Pure.hs24
1 files changed, 19 insertions, 5 deletions
diff --git a/Logs/Chunk/Pure.hs b/Logs/Chunk/Pure.hs
index 9bbfb868c..080a5a08b 100644
--- a/Logs/Chunk/Pure.hs
+++ b/Logs/Chunk/Pure.hs
@@ -6,7 +6,8 @@
-}
module Logs.Chunk.Pure
- ( ChunkSize
+ ( ChunkMethod(..)
+ , ChunkSize
, ChunkCount
, ChunkLog
, parseLog
@@ -17,24 +18,37 @@ import Common.Annex
import Logs.MapLog
import Data.Int
+-- Currently chunks are all fixed size, but other chunking methods
+-- may be added.
+data ChunkMethod = FixedSizeChunks ChunkSize | UnknownChunks String
+ deriving (Ord, Eq)
+
type ChunkSize = Int64
+-- 0 when chunks are no longer present
type ChunkCount = Integer
-type ChunkLog = MapLog (UUID, ChunkSize) ChunkCount
+type ChunkLog = MapLog (UUID, ChunkMethod) ChunkCount
+
+parseChunkMethod :: String -> ChunkMethod
+parseChunkMethod s = maybe (UnknownChunks s) FixedSizeChunks (readish s)
+
+showChunkMethod :: ChunkMethod -> String
+showChunkMethod (FixedSizeChunks sz) = show sz
+showChunkMethod (UnknownChunks s) = s
parseLog :: String -> ChunkLog
parseLog = parseMapLog fieldparser valueparser
where
fieldparser s =
- let (u,sz) = separate (== sep) s
- in (,) <$> pure (toUUID u) <*> readish sz
+ let (u,m) = separate (== sep) s
+ in Just (toUUID u, parseChunkMethod m)
valueparser = readish
showLog :: ChunkLog -> String
showLog = showMapLog fieldshower valueshower
where
- fieldshower (u, sz) = fromUUID u ++ sep : show sz
+ fieldshower (u, m) = fromUUID u ++ sep : showChunkMethod m
valueshower = show
sep :: Char