From a3daac8a8b06bbe2f35ca16cc1b27e21cad8a0e1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 2 Mar 2011 13:47:45 -0400 Subject: [PATCH] only enable SHA backends that configure finds support for --- Backend.hs | 3 ++- Backend/SHA.hs | 32 ++++++++++++++++++++++++-------- Backend/SHA1.hs | 14 -------------- Backend/SHA224.hs | 14 -------------- Backend/SHA384.hs | 14 -------------- Backend/SHA512.hs | 14 -------------- Backend/URL.hs | 5 ++++- Backend/WORM.hs | 5 ++++- BackendList.hs | 18 +++++------------- doc/install.mdwn | 2 +- doc/install/OSX.mdwn | 2 +- test.hs | 23 ++++++++++++++++------- 12 files changed, 57 insertions(+), 89 deletions(-) delete mode 100644 Backend/SHA1.hs delete mode 100644 Backend/SHA224.hs delete mode 100644 Backend/SHA384.hs delete mode 100644 Backend/SHA512.hs diff --git a/Backend.hs b/Backend.hs index 74f71f8bea..df23e80a33 100644 --- a/Backend.hs +++ b/Backend.hs @@ -26,7 +26,8 @@ module Backend ( fsckKey, lookupFile, chooseBackends, - keyBackend + keyBackend, + lookupBackendName ) where import Control.Monad.State diff --git a/Backend/SHA.hs b/Backend/SHA.hs index d779e80553..c074ab48a2 100644 --- a/Backend/SHA.hs +++ b/Backend/SHA.hs @@ -5,13 +5,14 @@ - Licensed under the GNU GPL version 3 or higher. -} -module Backend.SHA (genBackend) where +module Backend.SHA (backends) where import Control.Monad.State import Data.String.Utils import System.Cmd.Utils import System.IO import System.Directory +import Data.Maybe import qualified Backend.File import BackendTypes @@ -21,16 +22,31 @@ import Locations import Content import Types import Utility +import qualified SysConfig type SHASize = Int --- Constructor for Backends using a given SHASize. -genBackend :: SHASize -> Backend Annex -genBackend size = Backend.File.backend - { name = shaName size - , getKey = keyValue size - , fsckKey = Backend.File.checkKey $ checkKeyChecksum size - } +backends :: [Backend Annex] +-- order is slightly significant; want sha1 first ,and more general +-- sizes earlier +backends = catMaybes $ map genBackend [1, 256, 512, 224, 384] + +genBackend :: SHASize -> Maybe (Backend Annex) +genBackend size + | supported size = Just b + | otherwise = Nothing + where + b = Backend.File.backend + { name = shaName size + , getKey = keyValue size + , fsckKey = Backend.File.checkKey $ checkKeyChecksum size + } + supported 1 = SysConfig.sha1sum + supported 256 = SysConfig.sha256sum + supported 224 = SysConfig.sha224sum + supported 384 = SysConfig.sha384sum + supported 512 = SysConfig.sha512sum + supported _ = False shaName :: SHASize -> String shaName size = "SHA" ++ show size diff --git a/Backend/SHA1.hs b/Backend/SHA1.hs deleted file mode 100644 index 76d2af69e3..0000000000 --- a/Backend/SHA1.hs +++ /dev/null @@ -1,14 +0,0 @@ -{- git-annex "SHA1" backend - - - - Copyright 2011 Joey Hess - - - - Licensed under the GNU GPL version 3 or higher. - -} - -module Backend.SHA1 (backend) where - -import Types -import Backend.SHA - -backend :: Backend Annex -backend = genBackend 1 diff --git a/Backend/SHA224.hs b/Backend/SHA224.hs deleted file mode 100644 index 614f31c4b8..0000000000 --- a/Backend/SHA224.hs +++ /dev/null @@ -1,14 +0,0 @@ -{- git-annex "SHA224" backend - - - - Copyright 2011 Joey Hess - - - - Licensed under the GNU GPL version 3 or higher. - -} - -module Backend.SHA224 (backend) where - -import Types -import Backend.SHA - -backend :: Backend Annex -backend = genBackend 224 diff --git a/Backend/SHA384.hs b/Backend/SHA384.hs deleted file mode 100644 index 0cf77ea647..0000000000 --- a/Backend/SHA384.hs +++ /dev/null @@ -1,14 +0,0 @@ -{- git-annex "SHA384" backend - - - - Copyright 2011 Joey Hess - - - - Licensed under the GNU GPL version 3 or higher. - -} - -module Backend.SHA384 (backend) where - -import Types -import Backend.SHA - -backend :: Backend Annex -backend = genBackend 384 diff --git a/Backend/SHA512.hs b/Backend/SHA512.hs deleted file mode 100644 index aed8bbcedf..0000000000 --- a/Backend/SHA512.hs +++ /dev/null @@ -1,14 +0,0 @@ -{- git-annex "SHA512" backend - - - - Copyright 2011 Joey Hess - - - - Licensed under the GNU GPL version 3 or higher. - -} - -module Backend.SHA512 (backend) where - -import Types -import Backend.SHA - -backend :: Backend Annex -backend = genBackend 512 diff --git a/Backend/URL.hs b/Backend/URL.hs index 864c793010..29dc8fefa7 100644 --- a/Backend/URL.hs +++ b/Backend/URL.hs @@ -5,7 +5,7 @@ - Licensed under the GNU GPL version 3 or higher. -} -module Backend.URL (backend) where +module Backend.URL (backends) where import Control.Monad.State (liftIO) import Data.String.Utils @@ -15,6 +15,9 @@ import BackendTypes import Utility import Messages +backends :: [Backend Annex] +backends = [backend] + backend :: Backend Annex backend = Backend { name = "URL", diff --git a/Backend/WORM.hs b/Backend/WORM.hs index 92fe5a2d4c..8a6412eb11 100644 --- a/Backend/WORM.hs +++ b/Backend/WORM.hs @@ -5,7 +5,7 @@ - Licensed under the GNU GPL version 3 or higher. -} -module Backend.WORM (backend) where +module Backend.WORM (backends) where import Control.Monad.State import System.FilePath @@ -22,6 +22,9 @@ import Content import Messages import Types +backends :: [Backend Annex] +backends = [backend] + backend :: Backend Annex backend = Backend.File.backend { name = "WORM", diff --git a/BackendList.hs b/BackendList.hs index 4279b69fc9..bc3fd83142 100644 --- a/BackendList.hs +++ b/BackendList.hs @@ -9,21 +9,13 @@ module BackendList (allBackends) where -- When adding a new backend, import it here and add it to the list. import qualified Backend.WORM -import qualified Backend.SHA1 -import qualified Backend.SHA256 -import qualified Backend.SHA512 -import qualified Backend.SHA224 -import qualified Backend.SHA384 +import qualified Backend.SHA import qualified Backend.URL import Types allBackends :: [Backend Annex] -allBackends = - [ Backend.WORM.backend - , Backend.SHA1.backend - , Backend.SHA256.backend - , Backend.SHA512.backend - , Backend.SHA224.backend - , Backend.SHA384.backend - , Backend.URL.backend +allBackends = concat + [ Backend.WORM.backends + , Backend.SHA.backends + , Backend.URL.backends ] diff --git a/doc/install.mdwn b/doc/install.mdwn index f1305777c0..9eb8bbacf7 100644 --- a/doc/install.mdwn +++ b/doc/install.mdwn @@ -16,7 +16,7 @@ To build and use git-annex, you will need: (or uuidgen from util-linux) * `xargs`: * `rsync`: -* `sha1sum`: +* `sha1sum`: (optional, but recommended) * Then just [[download]] git-annex and run: `make; make install` ([Ikiwiki](http://ikiwiki.info) is needed to build the documentation, diff --git a/doc/install/OSX.mdwn b/doc/install/OSX.mdwn index af078e363d..3c29fc101c 100644 --- a/doc/install/OSX.mdwn +++ b/doc/install/OSX.mdwn @@ -7,7 +7,7 @@ sudo port install pcre sudo cabal install pcre-light sudo cabal install quickcheck -# this will enable the gnu tools, (to give sha224sum etc..., it does not override the BSD userland) +# optional: this will enable the gnu tools, (to give sha224sum etc..., it does not override the BSD userland) export PATH=$PATH:/opt/local/libexec/gnubin git clone git://git.kitenet.net/git-annex diff --git a/test.hs b/test.hs index 1bae3bd83e..6e35eaee59 100644 --- a/test.hs +++ b/test.hs @@ -37,8 +37,8 @@ import qualified UUID import qualified Trust import qualified Remotes import qualified Content -import qualified Backend.SHA1 -import qualified Backend.WORM +import qualified BackendList +import qualified Backend import qualified Command.DropUnused main :: IO () @@ -121,7 +121,7 @@ test_add = "git-annex add" ~: TestList [basic, sha1dup] test_setkey :: Test test_setkey = "git-annex setkey/fromkey" ~: TestCase $ inmainrepo $ do writeFile tmp $ content sha1annexedfile - r <- annexeval $ BackendTypes.getKey Backend.SHA1.backend tmp + r <- annexeval $ BackendTypes.getKey backendSHA1 tmp let sha1 = BackendTypes.keyName $ fromJust r git_annex "setkey" ["-q", "--backend", "SHA1", "--key", sha1, tmp] @? "setkey failed" git_annex "fromkey" ["-q", "--backend", "SHA1", "--key", sha1, sha1annexedfile] @? "fromkey failed" @@ -405,8 +405,8 @@ test_migrate = "git-annex migrate" ~: TestList [t False, t True] @? "migrate annexedfile failed" annexed_present annexedfile annexed_present sha1annexedfile - checkbackend annexedfile Backend.SHA1.backend - checkbackend sha1annexedfile Backend.SHA1.backend + checkbackend annexedfile backendSHA1 + checkbackend sha1annexedfile backendSHA1 -- check that reversing a migration works writeFile ".gitattributes" $ "* annex.backend=WORM" @@ -416,8 +416,8 @@ test_migrate = "git-annex migrate" ~: TestList [t False, t True] @? "migrate annexedfile failed" annexed_present annexedfile annexed_present sha1annexedfile - checkbackend annexedfile Backend.WORM.backend - checkbackend sha1annexedfile Backend.WORM.backend + checkbackend annexedfile backendWORM + checkbackend sha1annexedfile backendWORM where checkbackend file expected = do @@ -682,3 +682,12 @@ changecontent f = writeFile f $ changedcontent f changedcontent :: FilePath -> String changedcontent f = (content f) ++ " (modified)" + +backendSHA1 :: Types.Backend Types.Annex +backendSHA1 = backend_ "SHA1" + +backendWORM :: Types.Backend Types.Annex +backendWORM = backend_ "WORM" + +backend_ :: String -> Types.Backend Types.Annex +backend_ name = Backend.lookupBackendName BackendList.allBackends name