mincopies
This is conceptually very simple, just making a 1 that was hard coded be exposed as a config option. The hard part was plumbing all that, and dealing with complexities like reading it from git attributes at the same time that numcopies is read. Behavior change: When numcopies is set to 0, git-annex used to drop content without requiring any copies. Now to get that (highly unsafe) behavior, mincopies also needs to be set to 0. It seemed better to remove that edge case, than complicate mincopies by ignoring it when numcopies is 0. This commit was sponsored by Denis Dzyubenko on Patreon.
This commit is contained in:
parent
428d228ee5
commit
cc89699457
29 changed files with 412 additions and 219 deletions
|
@ -1,6 +1,6 @@
|
|||
{- git-annex numcopies log
|
||||
-
|
||||
- Copyright 2014 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2014-2021 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -9,8 +9,11 @@
|
|||
|
||||
module Logs.NumCopies (
|
||||
setGlobalNumCopies,
|
||||
setGlobalMinCopies,
|
||||
getGlobalNumCopies,
|
||||
getGlobalMinCopies,
|
||||
globalNumCopiesLoad,
|
||||
globalMinCopiesLoad,
|
||||
) where
|
||||
|
||||
import Annex.Common
|
||||
|
@ -23,19 +26,40 @@ instance SingleValueSerializable NumCopies where
|
|||
serialize (NumCopies n) = encodeBS (show n)
|
||||
deserialize = NumCopies <$$> readish . decodeBS
|
||||
|
||||
instance SingleValueSerializable MinCopies where
|
||||
serialize (MinCopies n) = encodeBS (show n)
|
||||
deserialize = MinCopies <$$> readish . decodeBS
|
||||
|
||||
setGlobalNumCopies :: NumCopies -> Annex ()
|
||||
setGlobalNumCopies new = do
|
||||
curr <- getGlobalNumCopies
|
||||
when (curr /= Just new) $
|
||||
setLog numcopiesLog new
|
||||
|
||||
setGlobalMinCopies :: MinCopies -> Annex ()
|
||||
setGlobalMinCopies new = do
|
||||
curr <- getGlobalMinCopies
|
||||
when (curr /= Just new) $
|
||||
setLog mincopiesLog new
|
||||
|
||||
{- Value configured in the numcopies log. Cached for speed. -}
|
||||
getGlobalNumCopies :: Annex (Maybe NumCopies)
|
||||
getGlobalNumCopies = maybe globalNumCopiesLoad (return . Just)
|
||||
=<< Annex.getState Annex.globalnumcopies
|
||||
|
||||
{- Value configured in the mincopies log. Cached for speed. -}
|
||||
getGlobalMinCopies :: Annex (Maybe MinCopies)
|
||||
getGlobalMinCopies = maybe globalMinCopiesLoad (return . Just)
|
||||
=<< Annex.getState Annex.globalmincopies
|
||||
|
||||
globalNumCopiesLoad :: Annex (Maybe NumCopies)
|
||||
globalNumCopiesLoad = do
|
||||
v <- getLog numcopiesLog
|
||||
Annex.changeState $ \s -> s { Annex.globalnumcopies = v }
|
||||
return v
|
||||
|
||||
globalMinCopiesLoad :: Annex (Maybe MinCopies)
|
||||
globalMinCopiesLoad = do
|
||||
v <- getLog mincopiesLog
|
||||
Annex.changeState $ \s -> s { Annex.globalmincopies = v }
|
||||
return v
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue