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