@@ -1,12 +1,15 @@
1module Main ( main ) where
1module Main ( main ) where
3import Control.Exception ( assert )
3import Control.Exception ( assert )
4+import Control.Monad ( when, filterM )
4import Data.Char ( toLower )
5import Data.Char ( toLower )
5import Data.List ( nubBy, sortBy )
6import Data.List ( nubBy, sortBy )
6import Data.Ord ( comparing )
7import Data.Ord ( comparing )
7import Data.Version ( Version(..) )
8import Data.Version ( Version(..) )
8import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
9import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
9import Distribution.Text ( simpleParse, display )
10import Distribution.Text ( simpleParse, display )
11+import System.Directory ( doesDirectoryExist, doesFileExist )
12+import System.FilePath ( (</>), (<.>) )
10import System.Process ( readProcess )
13import System.Process ( readProcess )
11import Text.Regex.Posix ( (=~), match, makeRegexOpts, compExtended, execBlank )
14import Text.Regex.Posix ( (=~), match, makeRegexOpts, compExtended, execBlank )
@@ -47,6 +50,10 @@ stripGhc721Versions pkgs = [ p | p@(_,_,attr) <- pkgs , not (attr =~ "ghc721") ]
47selectLatestVersions :: Pkgset -> Pkgset
50selectLatestVersions :: Pkgset -> Pkgset
48selectLatestVersions = nubBy (\x y -> comparePkgByName x y == EQ) . sortBy comparePkgByVersion
51selectLatestVersions = nubBy (\x y -> comparePkgByName x y == EQ) . sortBy comparePkgByVersion
53+isHackagePackage :: Pkg -> IO Bool
54+isHackagePackage (name,version,_) = doesFileExist path
55+ where path = "/dev/shm/hackage/" </> name </> display version </> name <.> "cabal"
50formatPackageLine :: Pkg -> String
57formatPackageLine :: Pkg -> String
51formatPackageLine (name,version,attr) = show (name, display version, Just url)
58formatPackageLine (name,version,attr) = show (name, display version, Just url)
@@ -59,5 +66,8 @@ regsubmatch buf patt = let (_,_,_,x) = f in x
60main :: IO ()
67main :: IO ()
69+ haveHackage <- doesDirectoryExist "/dev/shm/hackage"
70+ when (not haveHackage) (fail "cannot find hackage database at /dev/shm/hackage")
62− pkgset <- fmap (selectLatestVersions . stripGhc721Versions . stripProfilingVersions) getHaskellPackageList
71+ pkgset' <- fmap (selectLatestVersions . stripGhc721Versions . stripProfilingVersions) getHaskellPackageList
72+ pkgset <- filterM isHackagePackage pkgset'
63 mapM_ (putStrLn . formatPackageLine) (sortBy comparePkgByName pkgset)
73 mapM_ (putStrLn . formatPackageLine) (sortBy comparePkgByName pkgset)