summaryrefslogtreecommitdiff
path: root/Remote/Helper/Chunked.hs
blob: aafa6b700bb3444f3cae73403c1cde78f316623d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{- git-annex chunked remotes
 -
 - Copyright 2012-2014 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Remote.Helper.Chunked where

import Utility.DataUnits
import Types.Remote

import qualified Data.Map as M
import Data.Int

data ChunkConfig
	= NoChunks
	| ChunkSize Int64
	| LegacyChunkSize Int64

chunkConfig :: RemoteConfig -> ChunkConfig
chunkConfig m =
	case M.lookup "chunksize" m of
		Nothing -> case M.lookup "chunk" m of
			Nothing -> NoChunks
			Just v -> ChunkSize $ readsz v "chunk"
		Just v -> LegacyChunkSize $ readsz v "chunksize"
  where
	readsz v f = case readSize dataUnits v of
		Just size | size > 0 -> fromInteger size
		_ -> error ("bad " ++ f)