summaryrefslogtreecommitdiff
path: root/Logs/NumCopies.hs
blob: dc345dd0aa5a5d65437428d073194d8aa1117455 (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
32
33
{- git-annex numcopies log
 -
 - Copyright 2014 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

{-# OPTIONS_GHC -fno-warn-orphans #-}

module Logs.NumCopies where

import Common.Annex
import qualified Annex
import Logs
import Logs.SingleValue

instance Serializable Int where
	serialize = show
	deserialize = readish

setGlobalNumCopies :: Int -> Annex ()
setGlobalNumCopies = setLog numcopiesLog

{- Cached for speed. -}
getGlobalNumCopies :: Annex (Maybe Int)
getGlobalNumCopies = maybe numCopiesLoad (return . Just)
	=<< Annex.getState Annex.globalnumcopies

numCopiesLoad :: Annex (Maybe Int)
numCopiesLoad = do
	v <- getLog numcopiesLog
	Annex.changeState $ \s -> s { Annex.globalnumcopies = v }
	return v