2014-07-24 20:23:36 +00:00
|
|
|
{- Chunk logs, pure operations.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-07-24 20:23:36 +00:00
|
|
|
-
|
|
|
|
- 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
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2014-07-24 20:23:36 +00:00
|
|
|
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 = ':'
|