diff options
author | Fraser Tweedale <frase@frase.id.au> | 2011-04-08 10:08:11 +1000 |
---|---|---|
committer | Fraser Tweedale <frase@frase.id.au> | 2011-04-08 10:08:11 +1000 |
commit | f5b2d650bb75dc7ca2f77dae59fb1ab7f7405e03 (patch) | |
tree | b8dbb3f450e2ec18cdfe1128e9c21adfb6e2b953 | |
parent | bd1bbc21fac4b36975d03638d15e9aab915927cf (diff) |
recognise differently-named shaN programs
-rw-r--r-- | Backend/SHA.hs | 18 | ||||
-rw-r--r-- | TestConfig.hs | 14 | ||||
-rw-r--r-- | configure.hs | 9 |
3 files changed, 28 insertions, 13 deletions
diff --git a/Backend/SHA.hs b/Backend/SHA.hs index 0ec555ce3..42b5efeff 100644 --- a/Backend/SHA.hs +++ b/Backend/SHA.hs @@ -35,7 +35,7 @@ backends = catMaybes $ map genBackend [1, 256, 512, 224, 384] genBackend :: SHASize -> Maybe (Backend Annex) genBackend size - | supported size = Just b + | shaCommand size /= "" = Just b | otherwise = Nothing where b = Backend.File.backend @@ -43,12 +43,14 @@ genBackend 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 + +shaCommand :: SHASize -> String +shaCommand 1 = SysConfig.sha1 +shaCommand 256 = SysConfig.sha256 +shaCommand 224 = SysConfig.sha224 +shaCommand 384 = SysConfig.sha384 +shaCommand 512 = SysConfig.sha512 +shaCommand _ = "" shaName :: SHASize -> String shaName size = "SHA" ++ show size @@ -63,7 +65,7 @@ shaN size file = do then error $ command ++ " parse error" else return $ head bits where - command = "sha" ++ (show size) ++ "sum" + command = shaCommand size {- A key is a checksum of its contents. -} keyValue :: SHASize -> FilePath -> Annex (Maybe Key) diff --git a/TestConfig.hs b/TestConfig.hs index 5e59681dd..d1560b660 100644 --- a/TestConfig.hs +++ b/TestConfig.hs @@ -72,13 +72,25 @@ selectCmd k cmds = search cmds where search [] = do testEnd $ Config k (BoolConfig False) - error $ "* need one of these commands, but none are available: " ++ show cmds + error $ "* need one of these commands, but none are available: " ++ show (map (head . words) cmds) search (c:cs) = do ret <- system $ quiet c if (ret == ExitSuccess) then return $ Config k (StringConfig c) else search cs +whichCmd :: ConfigKey -> [String] -> Test +whichCmd k cmds = search cmds + where + search [] = do + testEnd $ Config k (StringConfig "") + return $ Config k (StringConfig "") + search (c:cs) = do + ret <- system $ quiet c + if (ret == ExitSuccess) + then return $ Config k (StringConfig $ head $ words c) + else search cs + quiet :: String -> String quiet s = s ++ " >/dev/null 2>&1" diff --git a/configure.hs b/configure.hs index f8cd577e9..c0e3d8106 100644 --- a/configure.hs +++ b/configure.hs @@ -20,10 +20,11 @@ tests = [ shaTestCases :: [Int] -> [TestCase] shaTestCases l = map make l - where - make n = - let cmd = "sha" ++ show n ++ "sum" - in TestCase cmd $ requireCmd cmd (cmd ++ " </dev/null") + where make n = + let + cmds = map (\x -> "sha" ++ show n ++ x ++ " </dev/null") ["", "sum"] + key = "sha" ++ show n + in TestCase key $ whichCmd key cmds tmpDir :: String tmpDir = "tmp" |