vicfg: Include mincopies configuration

Sponsored-by: k0ld on Patreon
This commit is contained in:
Joey Hess 2022-09-15 15:11:59 -04:00
parent 9164d9587c
commit 451a7ce77f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 11 additions and 1 deletions

View file

@ -13,6 +13,7 @@ git-annex (10.20220823) UNRELEASED; urgency=medium
* Fix a reversion that made dead keys not be skipped when operating on * Fix a reversion that made dead keys not be skipped when operating on
all keys via --all or in a bare repo. all keys via --all or in a bare repo.
(Introduced in version 8.20200720) (Introduced in version 8.20200720)
* vicfg: Include mincopies configuration.
-- Joey Hess <id@joeyh.name> Mon, 29 Aug 2022 15:03:04 -0400 -- Joey Hess <id@joeyh.name> Mon, 29 Aug 2022 15:03:04 -0400

View file

@ -1,6 +1,6 @@
{- git-annex command {- git-annex command
- -
- Copyright 2012-2017 Joey Hess <id@joeyh.name> - Copyright 2012-2022 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -75,6 +75,7 @@ data Cfg = Cfg
, cfgScheduleMap :: M.Map UUID [ScheduledActivity] , cfgScheduleMap :: M.Map UUID [ScheduledActivity]
, cfgGlobalConfigs :: M.Map ConfigKey ConfigValue , cfgGlobalConfigs :: M.Map ConfigKey ConfigValue
, cfgNumCopies :: Maybe NumCopies , cfgNumCopies :: Maybe NumCopies
, cfgMinCopies :: Maybe MinCopies
} }
getCfg :: Annex Cfg getCfg :: Annex Cfg
@ -87,6 +88,7 @@ getCfg = Cfg
<*> scheduleMap <*> scheduleMap
<*> loadGlobalConfig <*> loadGlobalConfig
<*> getGlobalNumCopies <*> getGlobalNumCopies
<*> getGlobalMinCopies
setCfg :: Cfg -> Cfg -> Annex () setCfg :: Cfg -> Cfg -> Annex ()
setCfg curcfg newcfg = do setCfg curcfg newcfg = do
@ -99,6 +101,7 @@ setCfg curcfg newcfg = do
mapM_ (uncurry scheduleSet) $ M.toList $ cfgScheduleMap diff mapM_ (uncurry scheduleSet) $ M.toList $ cfgScheduleMap diff
mapM_ (uncurry setGlobalConfig) $ M.toList $ cfgGlobalConfigs diff mapM_ (uncurry setGlobalConfig) $ M.toList $ cfgGlobalConfigs diff
maybe noop setGlobalNumCopies $ cfgNumCopies diff maybe noop setGlobalNumCopies $ cfgNumCopies diff
maybe noop setGlobalMinCopies $ cfgMinCopies diff
{- Default config has all the keys from the input config, but with their {- Default config has all the keys from the input config, but with their
- default values. -} - default values. -}
@ -112,6 +115,7 @@ defCfg curcfg = Cfg
, cfgScheduleMap = mapdef $ cfgScheduleMap curcfg , cfgScheduleMap = mapdef $ cfgScheduleMap curcfg
, cfgGlobalConfigs = mapdef $ cfgGlobalConfigs curcfg , cfgGlobalConfigs = mapdef $ cfgGlobalConfigs curcfg
, cfgNumCopies = Nothing , cfgNumCopies = Nothing
, cfgMinCopies = Nothing
} }
where where
mapdef :: forall k v. Default v => M.Map k v -> M.Map k v mapdef :: forall k v. Default v => M.Map k v -> M.Map k v
@ -127,6 +131,7 @@ diffCfg curcfg newcfg = Cfg
, cfgScheduleMap = diff cfgScheduleMap , cfgScheduleMap = diff cfgScheduleMap
, cfgGlobalConfigs = diff cfgGlobalConfigs , cfgGlobalConfigs = diff cfgGlobalConfigs
, cfgNumCopies = cfgNumCopies newcfg , cfgNumCopies = cfgNumCopies newcfg
, cfgMinCopies = cfgMinCopies newcfg
} }
where where
diff f = M.differenceWith (\x y -> if x == y then Nothing else Just x) diff f = M.differenceWith (\x y -> if x == y then Nothing else Just x)
@ -236,6 +241,7 @@ genCfg cfg descs = unlines $ intercalate [""]
numcopies = numcopies =
[ com "Numcopies configuration" [ com "Numcopies configuration"
, line' "numcopies" (show . fromNumCopies <$> cfgNumCopies cfg) , line' "numcopies" (show . fromNumCopies <$> cfgNumCopies cfg)
, line' "mincopies" (show . fromMinCopies <$> cfgMinCopies cfg)
] ]
settings :: Ord v => Cfg -> UUIDDescMap -> (Cfg -> M.Map UUID v) -> [String] -> ((v, UUID) -> [String]) -> (UUID -> [String]) -> [String] settings :: Ord v => Cfg -> UUIDDescMap -> (Cfg -> M.Map UUID v) -> [String] -> ((v, UUID) -> [String]) -> (UUID -> [String]) -> [String]
@ -316,6 +322,9 @@ parseCfg defcfg = go [] defcfg . lines
| setting == "numcopies" = case readish val of | setting == "numcopies" = case readish val of
Nothing -> Left "parse error (expected an integer)" Nothing -> Left "parse error (expected an integer)"
Just n -> Right $ cfg { cfgNumCopies = Just (configuredNumCopies n) } Just n -> Right $ cfg { cfgNumCopies = Just (configuredNumCopies n) }
| setting == "mincopies" = case readish val of
Nothing -> Left "parse error (expected an integer)"
Just n -> Right $ cfg { cfgMinCopies = Just (configuredMinCopies n) }
| otherwise = badval "setting" setting | otherwise = badval "setting" setting
where where
u = toUUID f u = toUUID f