2014-07-24 20:23:36 +00:00
|
|
|
{- Chunk logs, pure operations.
|
|
|
|
-
|
|
|
|
- Copyright 2014 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2014-07-24 21:18:14 +00:00
|
|
|
module Logs.Chunk.Pure
|
2014-07-28 17:19:08 +00:00
|
|
|
( ChunkMethod(..)
|
|
|
|
, ChunkSize
|
2014-07-24 21:18:14 +00:00
|
|
|
, ChunkCount
|
|
|
|
, ChunkLog
|
|
|
|
, parseLog
|
|
|
|
, showLog
|
|
|
|
) where
|
2014-07-24 20:23:36 +00:00
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Logs.MapLog
|
|
|
|
import Data.Int
|
|
|
|
|
2014-07-28 17:19:08 +00:00
|
|
|
-- Currently chunks are all fixed size, but other chunking methods
|
|
|
|
-- may be added.
|
|
|
|
data ChunkMethod = FixedSizeChunks ChunkSize | UnknownChunks String
|
2014-08-01 20:30:23 +00:00
|
|
|
deriving (Ord, Eq, Show)
|
2014-07-28 17:19:08 +00:00
|
|
|
|
2014-07-24 20:23:36 +00:00
|
|
|
type ChunkSize = Int64
|
|
|
|
|
2014-07-28 17:19:08 +00:00
|
|
|
-- 0 when chunks are no longer present
|
2014-07-24 20:23:36 +00:00
|
|
|
type ChunkCount = Integer
|
|
|
|
|
2014-07-28 17:19:08 +00:00
|
|
|
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
|
2014-07-24 20:23:36 +00:00
|
|
|
|
|
|
|
parseLog :: String -> ChunkLog
|
|
|
|
parseLog = parseMapLog fieldparser valueparser
|
|
|
|
where
|
|
|
|
fieldparser s =
|
2014-07-28 17:19:08 +00:00
|
|
|
let (u,m) = separate (== sep) s
|
|
|
|
in Just (toUUID u, parseChunkMethod m)
|
2014-07-24 20:23:36 +00:00
|
|
|
valueparser = readish
|
|
|
|
|
|
|
|
showLog :: ChunkLog -> String
|
|
|
|
showLog = showMapLog fieldshower valueshower
|
|
|
|
where
|
2014-07-28 17:19:08 +00:00
|
|
|
fieldshower (u, m) = fromUUID u ++ sep : showChunkMethod m
|
2014-07-24 20:23:36 +00:00
|
|
|
valueshower = show
|
2014-07-24 21:18:14 +00:00
|
|
|
|
|
|
|
sep :: Char
|
|
|
|
sep = ':'
|