@@ -12,6 +12,7 @@ import System.Exit
1212import Distribution.PackageDescription.Parse
1313import Distribution.PackageDescription
1414import Distribution.Package
15+import Distribution.Text
1516import Data.Version
1617import Data.List
1718import Data.Maybe
@@ -41,19 +42,27 @@ simplify (CondNode _ deps nodes) = CondNode () deps (map simp nodes)
4142 where
4243 simp (cond,tree,mtree) = (cond, simplify tree, maybe Nothing (Just . simplify) mtree)
4344
44−hackagePath :: PackageIdentifier -> String -> String
45+data Ext = TarGz | Cabal deriving Eq
46+
47+showExt :: Ext -> String
48+showExt TarGz = ".tar.gz"
49+showExt Cabal = ".cabal"
50+
51+hackagePath :: PackageIdentifier -> Ext -> String
4552hackagePath (PackageIdentifier (PackageName name) version') ext =
4653 "http://hackage.haskell.org/packages/archive/" ++
47− name ++ "/" ++ version ++ "/" ++ name ++ "-" ++ version ++
48− "." ++ ext
54+ name ++ "/" ++ version ++ "/" ++ name ++
55+ (if ext == TarGz then "-" ++ version else "") ++
56+ showExt ext
4957 where
5058 version = showVersion version'
5159
5260readCabalFile :: FilePath -> IO String
5361readCabalFile path
54− | "http://" `isPrefixOf` path = Network.HTTP.simpleHTTP (getRequest path) >>= getResponseBody
55− | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
56− | otherwise = readFile path
62+ | "cabal://" `isPrefixOf` path = let Just pid = simpleParse (drop 8 path) in readCabalFile (hackagePath pid Cabal)
63+ | "http://" `isPrefixOf` path = Network.HTTP.simpleHTTP (getRequest path) >>= getResponseBody
64+ | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
65+ | otherwise = readFile path
5766
5867hashPackage :: GenericPackageDescription -> IO String
5968hashPackage pkg = do
@@ -61,7 +70,7 @@ hashPackage pkg = do
6170 return (reverse (dropWhile (=='\n') (reverse hash)))
6271
6372 where
64− url = hackagePath pid ".tar.gz"
73+ url = hackagePath pid TarGz
6574 pid = package (packageDescription pkg)
6675
6776main :: IO ()