module Distribution.Hackage.DB.Path where
import Distribution.Hackage.DB.Errors
import Control.Exception
import System.Directory
import System.FilePath
cabalStateDir :: IO FilePath
cabalStateDir = getAppUserDataDirectory "cabal"
cabalTarballDir :: String -> IO FilePath
cabalTarballDir repo = do
csd <- cabalStateDir
return $ joinPath [csd, "packages", repo]
hackageTarballDir :: IO FilePath
hackageTarballDir = cabalTarballDir "hackage.haskell.org"
hackageTarball :: IO FilePath
hackageTarball = do
htd <- hackageTarballDir
let idx00 = htd </> "00-index.tar"
idx01 = htd </> "01-index.tar"
have01 <- doesFileExist idx01
if have01 then return idx01 else do
have00 <- doesFileExist idx00
if have00 then return idx00 else
throwIO NoHackageTarballFound