git-annex/Logs/NumCopies.hs
Joey Hess 26d23e38f1
vicfg: Include the numcopies configuation.
Docs say vicfg can configure everything from git-annex branch,
so it ought to configure numcopies.

Note that commenting out existing numcopies does not unset it.

This commit was sponsored by Thom May on Patreon.
2017-01-30 15:27:25 -04:00

41 lines
1 KiB
Haskell

{- git-annex numcopies log
-
- Copyright 2014 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Logs.NumCopies (
setGlobalNumCopies,
getGlobalNumCopies,
globalNumCopiesLoad,
) where
import Annex.Common
import qualified Annex
import Types.NumCopies
import Logs
import Logs.SingleValue
instance SingleValueSerializable NumCopies where
serialize (NumCopies n) = show n
deserialize = NumCopies <$$> readish
setGlobalNumCopies :: NumCopies -> Annex ()
setGlobalNumCopies new = do
curr <- getGlobalNumCopies
when (curr /= Just new) $
setLog numcopiesLog new
{- Value configured in the numcopies log. Cached for speed. -}
getGlobalNumCopies :: Annex (Maybe NumCopies)
getGlobalNumCopies = maybe globalNumCopiesLoad (return . Just)
=<< Annex.getState Annex.globalnumcopies
globalNumCopiesLoad :: Annex (Maybe NumCopies)
globalNumCopiesLoad = do
v <- getLog numcopiesLog
Annex.changeState $ \s -> s { Annex.globalnumcopies = v }
return v