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
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# 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
|
|
|
|
serialize (NumCopies n) = show n
|
|
|
|
deserialize = NumCopies <$$> readish
|
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
|