diff --git a/Annex/Drop.hs b/Annex/Drop.hs index 8cab7b0650..09ca822a35 100644 --- a/Annex/Drop.hs +++ b/Annex/Drop.hs @@ -9,7 +9,7 @@ module Annex.Drop where import Common.Annex import Logs.Trust -import Logs.NumCopies +import Config.NumCopies import Types.Remote (uuid) import qualified Remote import qualified Command.Drop diff --git a/Assistant/WebApp/Configurators/Preferences.hs b/Assistant/WebApp/Configurators/Preferences.hs index d5e78d645d..d4783e7422 100644 --- a/Assistant/WebApp/Configurators/Preferences.hs +++ b/Assistant/WebApp/Configurators/Preferences.hs @@ -17,11 +17,11 @@ import qualified Annex import qualified Git import Config import Config.Files +import Config.NumCopies import Utility.DataUnits import Git.Config import Types.Distribution import qualified Build.SysConfig -import Logs.NumCopies import qualified Data.Text as T diff --git a/Command/Copy.hs b/Command/Copy.hs index 090bd3a9a0..395992ed0c 100644 --- a/Command/Copy.hs +++ b/Command/Copy.hs @@ -13,7 +13,7 @@ import GitAnnex.Options import qualified Command.Move import qualified Remote import Annex.Wanted -import Logs.NumCopies +import Config.NumCopies def :: [Command] def = [withOptions Command.Move.moveOptions $ command "copy" paramPaths seek diff --git a/Command/Drop.hs b/Command/Drop.hs index 8f7e1aae98..bf832e8d59 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -14,7 +14,7 @@ import qualified Annex import Annex.UUID import Logs.Location import Logs.Trust -import Logs.NumCopies +import Config.NumCopies import Annex.Content import qualified Option import Annex.Wanted diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs index 043ddfe001..af90303fb9 100644 --- a/Command/DropUnused.hs +++ b/Command/DropUnused.hs @@ -15,7 +15,7 @@ import qualified Remote import qualified Git import qualified Option import Command.Unused (withUnusedMaps, UnusedMaps(..), startUnused) -import Logs.NumCopies +import Config.NumCopies def :: [Command] def = [withOptions [Command.Drop.fromOption] $ diff --git a/Command/Fsck.hs b/Command/Fsck.hs index 5980251895..8928235846 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -25,7 +25,7 @@ import Annex.Perms import Annex.Link import Logs.Location import Logs.Trust -import Logs.NumCopies +import Config.NumCopies import Annex.UUID import Utility.DataUnits import Utility.FileMode diff --git a/Command/Get.hs b/Command/Get.hs index 74d5068d3d..cdb85af944 100644 --- a/Command/Get.hs +++ b/Command/Get.hs @@ -12,7 +12,7 @@ import Command import qualified Remote import Annex.Content import Logs.Transfer -import Logs.NumCopies +import Config.NumCopies import Annex.Wanted import GitAnnex.Options import qualified Command.Move diff --git a/Command/Info.hs b/Command/Info.hs index c62dc38445..c36ae8eed0 100644 --- a/Command/Info.hs +++ b/Command/Info.hs @@ -29,7 +29,7 @@ import Annex.Content import Types.Key import Logs.UUID import Logs.Trust -import Logs.NumCopies +import Config.NumCopies import Remote import Config import Utility.Percentage diff --git a/Command/Mirror.hs b/Command/Mirror.hs index fb06ed2b43..49208065ba 100644 --- a/Command/Mirror.hs +++ b/Command/Mirror.hs @@ -16,7 +16,7 @@ import qualified Command.Get import qualified Remote import Annex.Content import qualified Annex -import Logs.NumCopies +import Config.NumCopies def :: [Command] def = [withOptions (fromToOptions ++ keyOptions) $ diff --git a/Command/NumCopies.hs b/Command/NumCopies.hs index cc322bcbd5..b7323ae357 100644 --- a/Command/NumCopies.hs +++ b/Command/NumCopies.hs @@ -10,7 +10,7 @@ module Command.NumCopies where import Common.Annex import qualified Annex import Command -import Logs.NumCopies +import Config.NumCopies import Types.Messages def :: [Command] diff --git a/Config/NumCopies.hs b/Config/NumCopies.hs new file mode 100644 index 0000000000..26d81b8a4c --- /dev/null +++ b/Config/NumCopies.hs @@ -0,0 +1,80 @@ +{- git-annex numcopies configuration + - + - Copyright 2014 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Config.NumCopies ( + module Types.NumCopies, + module Logs.NumCopies, + getFileNumCopies, + getGlobalFileNumCopies, + getNumCopies, + numCopiesCheck, + deprecatedNumCopies, + defaultNumCopies +) where + +import Common.Annex +import qualified Annex +import Types.NumCopies +import Logs.NumCopies +import Logs.Trust +import Annex.CheckAttr +import qualified Remote + +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. -} +numCopiesCheck :: FilePath -> Key -> (Int -> Int -> v) -> Annex v +numCopiesCheck file key vs = do + NumCopies needed <- getFileNumCopies file + have <- trustExclude UnTrusted =<< Remote.keyLocations key + return $ length have `vs` needed diff --git a/Limit.hs b/Limit.hs index 9d62fecc1e..471a0c278b 100644 --- a/Limit.hs +++ b/Limit.hs @@ -23,7 +23,7 @@ import qualified Backend import Annex.Content import Annex.UUID import Logs.Trust -import Logs.NumCopies +import Config.NumCopies import Types.TrustLevel import Types.Key import Types.Group diff --git a/Logs/NumCopies.hs b/Logs/NumCopies.hs index 8f1a093015..5cce61ce62 100644 --- a/Logs/NumCopies.hs +++ b/Logs/NumCopies.hs @@ -8,16 +8,9 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Logs.NumCopies ( - module Types.NumCopies, setGlobalNumCopies, getGlobalNumCopies, globalNumCopiesLoad, - getFileNumCopies, - getGlobalFileNumCopies, - getNumCopies, - numCopiesCheck, - deprecatedNumCopies, - defaultNumCopies ) where import Common.Annex @@ -25,9 +18,6 @@ import qualified Annex import Types.NumCopies import Logs import Logs.SingleValue -import Logs.Trust -import Annex.CheckAttr -import qualified Remote instance SingleValueSerializable NumCopies where serialize (NumCopies n) = show n @@ -46,58 +36,3 @@ globalNumCopiesLoad = do v <- getLog numcopiesLog Annex.changeState $ \s -> s { Annex.globalnumcopies = v } return v - -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. -} -numCopiesCheck :: FilePath -> Key -> (Int -> Int -> v) -> Annex v -numCopiesCheck file key vs = do - NumCopies needed <- getFileNumCopies file - have <- trustExclude UnTrusted =<< Remote.keyLocations key - return $ length have `vs` needed diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs index af516d27ac..e19fdc42fe 100644 --- a/Types/GitConfig.hs +++ b/Types/GitConfig.hs @@ -79,7 +79,6 @@ extractGitConfig r = GitConfig , gcryptId = getmaybe "core.gcrypt-id" } where - get k def = fromMaybe def $ getmayberead k getbool k def = fromMaybe def $ getmaybebool k getmaybebool k = Git.Config.isTrue =<< getmaybe k getmayberead k = readish =<< getmaybe k