2014-01-20 20:47:56 +00:00
|
|
|
{- git-annex numcopies log
|
|
|
|
-
|
2021-01-06 18:11:08 +00:00
|
|
|
- Copyright 2014-2021 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,
|
2021-01-06 18:11:08 +00:00
|
|
|
setGlobalMinCopies,
|
2014-01-21 20:08:19 +00:00
|
|
|
getGlobalNumCopies,
|
2021-01-06 18:11:08 +00:00
|
|
|
getGlobalMinCopies,
|
2014-01-21 20:08:19 +00:00
|
|
|
globalNumCopiesLoad,
|
2021-01-06 18:11:08 +00:00
|
|
|
globalMinCopiesLoad,
|
2014-01-21 20:08:19 +00:00
|
|
|
) 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
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
instance SingleValueSerializable MinCopies where
|
|
|
|
serialize (MinCopies n) = encodeBS (show n)
|
|
|
|
deserialize = MinCopies <$$> readish . decodeBS
|
|
|
|
|
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
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
setGlobalMinCopies :: MinCopies -> Annex ()
|
|
|
|
setGlobalMinCopies new = do
|
|
|
|
curr <- getGlobalMinCopies
|
|
|
|
when (curr /= Just new) $
|
|
|
|
setLog mincopiesLog new
|
|
|
|
|
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
|
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
{- Value configured in the mincopies log. Cached for speed. -}
|
|
|
|
getGlobalMinCopies :: Annex (Maybe MinCopies)
|
|
|
|
getGlobalMinCopies = maybe globalMinCopiesLoad (return . Just)
|
|
|
|
=<< Annex.getState Annex.globalmincopies
|
|
|
|
|
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
|
2021-01-06 18:11:08 +00:00
|
|
|
|
|
|
|
globalMinCopiesLoad :: Annex (Maybe MinCopies)
|
|
|
|
globalMinCopiesLoad = do
|
|
|
|
v <- getLog mincopiesLog
|
|
|
|
Annex.changeState $ \s -> s { Annex.globalmincopies = v }
|
|
|
|
return v
|