2014-01-20 20:47:56 +00:00
|
|
|
{- git-annex numcopies log
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-01-20 20:47:56 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-01-20 20:47:56 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
2014-01-21 20:08:19 +00:00
|
|
|
module Logs.NumCopies (
|
|
|
|
setGlobalNumCopies,
|
|
|
|
getGlobalNumCopies,
|
|
|
|
globalNumCopiesLoad,
|
|
|
|
) where
|
2014-01-20 20:47:56 +00:00
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2014-01-20 20:47:56 +00:00
|
|
|
import qualified Annex
|
2014-01-21 20:08:19 +00:00
|
|
|
import Types.NumCopies
|
2014-01-20 20:47:56 +00:00
|
|
|
import Logs
|
|
|
|
import Logs.SingleValue
|
|
|
|
|
2014-01-21 20:08:19 +00:00
|
|
|
instance SingleValueSerializable NumCopies where
|
2019-01-07 19:51:05 +00:00
|
|
|
serialize (NumCopies n) = encodeBS (show n)
|
|
|
|
deserialize = NumCopies <$$> readish . decodeBS
|
2014-01-20 20:47:56 +00:00
|
|
|
|
2014-01-21 20:08:19 +00:00
|
|
|
setGlobalNumCopies :: NumCopies -> Annex ()
|
2017-01-30 19:11:26 +00:00
|
|
|
setGlobalNumCopies new = do
|
|
|
|
curr <- getGlobalNumCopies
|
|
|
|
when (curr /= Just new) $
|
|
|
|
setLog numcopiesLog new
|
2014-01-20 20:47:56 +00:00
|
|
|
|
2014-01-21 21:08:49 +00:00
|
|
|
{- Value configured in the numcopies log. Cached for speed. -}
|
2014-01-21 20:08:19 +00:00
|
|
|
getGlobalNumCopies :: Annex (Maybe NumCopies)
|
|
|
|
getGlobalNumCopies = maybe globalNumCopiesLoad (return . Just)
|
2014-01-20 20:47:56 +00:00
|
|
|
=<< Annex.getState Annex.globalnumcopies
|
|
|
|
|
2014-01-21 20:08:19 +00:00
|
|
|
globalNumCopiesLoad :: Annex (Maybe NumCopies)
|
|
|
|
globalNumCopiesLoad = do
|
2014-01-20 20:47:56 +00:00
|
|
|
v <- getLog numcopiesLog
|
|
|
|
Annex.changeState $ \s -> s { Annex.globalnumcopies = v }
|
|
|
|
return v
|