diff options
author | Joey Hess <joey@kitenet.net> | 2014-01-21 17:08:49 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-01-21 17:25:39 -0400 |
commit | d44bd607d4fd18eadabe3c7693ebcf1c74aae63e (patch) | |
tree | 83e8867f45199ece960fc67e4d31f1d9b4a5d56a /Logs | |
parent | d5f7fb27aad3e2e9c4bebb9ccd5577af8deb25c7 (diff) |
numcopies cleanup, part 2
This includes several bug fixes.
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/NumCopies.hs | 80 |
1 files changed, 53 insertions, 27 deletions
diff --git a/Logs/NumCopies.hs b/Logs/NumCopies.hs index 2fd6f75f8..8f1a09301 100644 --- a/Logs/NumCopies.hs +++ b/Logs/NumCopies.hs @@ -13,9 +13,11 @@ module Logs.NumCopies ( getGlobalNumCopies, globalNumCopiesLoad, getFileNumCopies, - numCopiesCheck, + getGlobalFileNumCopies, getNumCopies, + numCopiesCheck, deprecatedNumCopies, + defaultNumCopies ) where import Common.Annex @@ -34,7 +36,7 @@ instance SingleValueSerializable NumCopies where setGlobalNumCopies :: NumCopies -> Annex () setGlobalNumCopies = setLog numcopiesLog -{- Cached for speed. -} +{- Value configured in the numcopies log. Cached for speed. -} getGlobalNumCopies :: Annex (Maybe NumCopies) getGlobalNumCopies = maybe globalNumCopiesLoad (return . Just) =<< Annex.getState Annex.globalnumcopies @@ -45,33 +47,57 @@ globalNumCopiesLoad = do Annex.changeState $ \s -> s { Annex.globalnumcopies = v } return v -{- Numcopies value for a file, from .gitattributes or global, - - but not the deprecated git config. -} -getFileNumCopies :: FilePath -> Annex (Maybe NumCopies) -getFileNumCopies file = do - global <- getGlobalNumCopies - case global of - Just n -> return $ Just n - Nothing -> (NumCopies <$$> readish) - <$> checkAttr "annex.numcopies" file - -deprecatedNumCopies :: Annex NumCopies -deprecatedNumCopies = NumCopies . fromMaybe 1 . annexNumCopies - <$> Annex.getGitConfig - -{- Checks if numcopies are satisfied by running a comparison +defaultNumCopies :: NumCopies +defaultNumCopies = NumCopies 1 + +fromSources :: [Annex (Maybe NumCopies)] -> Annex NumCopies +fromSources = fromMaybe defaultNumCopies <$$> getM id + +{- The git config annex.numcopies is deprecated. -} +deprecatedNumCopies :: Annex (Maybe NumCopies) +deprecatedNumCopies = annexNumCopies <$> Annex.getGitConfig + +{- Value forced on the command line by --numcopies. -} +getForcedNumCopies :: Annex (Maybe NumCopies) +getForcedNumCopies = Annex.getState Annex.forcenumcopies + +{- Numcopies value from any of the non-.gitattributes configuration + - sources. -} +getNumCopies :: Annex NumCopies +getNumCopies = fromSources + [ getForcedNumCopies + , getGlobalNumCopies + , deprecatedNumCopies + ] + +{- Numcopies value for a file, from any configuration source, including the + - deprecated git config. -} +getFileNumCopies :: FilePath -> Annex NumCopies +getFileNumCopies f = fromSources + [ getForcedNumCopies + , getFileNumCopies' f + , deprecatedNumCopies + ] + +{- This is the globally visible numcopies value for a file. So it does + - not include local configuration in the git config or command line + - options. -} +getGlobalFileNumCopies :: FilePath -> Annex NumCopies +getGlobalFileNumCopies f = fromSources + [ getFileNumCopies' f + ] + +getFileNumCopies' :: FilePath -> Annex (Maybe NumCopies) +getFileNumCopies' file = maybe getGlobalNumCopies (return . Just) =<< getattr + where + getattr = (NumCopies <$$> readish) + <$> checkAttr "annex.numcopies" file + +{- Checks if numcopies are satisfied for a file by running a comparison - between the number of (not untrusted) copies that are - - belived to exist, and the configured value. - - - - Includes the deprecated annex.numcopies git config if - - nothing else specifies a numcopies value. -} + - belived to exist, and the configured value. -} numCopiesCheck :: FilePath -> Key -> (Int -> Int -> v) -> Annex v numCopiesCheck file key vs = do - numcopiesattr <- getFileNumCopies file - NumCopies needed <- getNumCopies numcopiesattr + NumCopies needed <- getFileNumCopies file have <- trustExclude UnTrusted =<< Remote.keyLocations key return $ length have `vs` needed - -getNumCopies :: Maybe NumCopies -> Annex NumCopies -getNumCopies (Just v) = return v -getNumCopies Nothing = deprecatedNumCopies |