git-annex/Logs/Chunk/Pure.hs

56 lines
1.2 KiB
Haskell
Raw Normal View History

{- 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
( ChunkMethod(..)
, ChunkSize
2014-07-24 21:18:14 +00:00
, ChunkCount
, ChunkLog
, parseLog
, showLog
) where
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
2014-08-01 20:30:23 +00:00
deriving (Ord, Eq, Show)
type ChunkSize = Int64
-- 0 when chunks are no longer present
type ChunkCount = Integer
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,m) = separate (== sep) s
in Just (toUUID u, parseChunkMethod m)
valueparser = readish
showLog :: ChunkLog -> String
showLog = showMapLog fieldshower valueshower
where
fieldshower (u, m) = fromUUID u ++ sep : showChunkMethod m
valueshower = show
2014-07-24 21:18:14 +00:00
sep :: Char
sep = ':'