Commit 7410e516 authored by bjorn@bringert.net's avatar bjorn@bringert.net
Browse files

cabal-install now puts the package list in /var/lib/cabal-install and the...

cabal-install now puts the package list in /var/lib/cabal-install and the tarballs in /var/cache/cabal-install by default. Added command-line options for changing those.
parent 3a7c3473
......@@ -11,7 +11,10 @@
-- Utilities for handling saved state such as known packages, known servers and downloaded packages.
-----------------------------------------------------------------------------
module Network.Hackage.CabalInstall.Config
( packagesDirectoryName
( packagesDirectory
, defaultConfDir
, defaultCacheDir
, defaultPkgListDir
, getKnownServers
, getKnownPackages
, writeKnownPackages
......@@ -21,7 +24,7 @@ module Network.Hackage.CabalInstall.Config
import Prelude hiding (catch)
import Control.Exception (catch, Exception(IOException))
import Control.Monad.Error (mplus, filterM) -- Using Control.Monad.Error to get the Error instance for IO.
import System.Directory (Permissions (..), getPermissions)
import System.Directory (Permissions (..), getPermissions, createDirectoryIfMissing)
import System.IO.Error (isDoesNotExistError)
import System.IO (hPutStrLn, stderr)
......@@ -31,6 +34,18 @@ import Distribution.Compat.FilePath (joinFileName)
import Network.Hackage.CabalInstall.Types (ConfigFlags (..), PkgInfo (..))
-- FIXME: should be different on Windows
defaultConfDir :: FilePath
defaultConfDir = "/etc/cabal-install"
-- FIXME: should be different on Windows
defaultCacheDir :: FilePath
defaultCacheDir = "/var/cache/cabal-install"
-- FIXME: should be different on Windows
defaultPkgListDir :: FilePath
defaultPkgListDir = "/var/lib/cabal-install"
pkgListFile :: FilePath
pkgListFile = "pkg.list"
......@@ -41,11 +56,18 @@ servListFile = "serv.list"
packagesDirectoryName :: FilePath
packagesDirectoryName = "packages"
-- | Full path to the server list file
servList :: ConfigFlags -> FilePath
servList cfg = configConfDir cfg `joinFileName` servListFile
-- | Full path to the packages directory.
packagesDirectory :: ConfigFlags -> FilePath
packagesDirectory cfg = configCacheDir cfg `joinFileName` packagesDirectoryName
-- | Full path to the package list file
pkgList :: ConfigFlags -> FilePath
pkgList cfg = configConfPath cfg `joinFileName` pkgListFile
pkgList cfg = configPkgListDir cfg `joinFileName` pkgListFile
servList :: ConfigFlags -> FilePath
servList cfg = configConfPath cfg `joinFileName` servListFile
-- |Read the list of known packages from the pkg.list file.
getKnownPackages :: ConfigFlags -> IO [PkgInfo]
......@@ -65,7 +87,8 @@ getKnownPackages cfg
-- |Write the list of known packages to the pkg.list file.
writeKnownPackages :: ConfigFlags -> [PkgInfo] -> IO ()
writeKnownPackages cfg pkgs
= writeFile (pkgList cfg) (show pkgs)
= do createDirectoryIfMissing True (configPkgListDir cfg)
writeFile (pkgList cfg) (show pkgs)
getKnownServers :: ConfigFlags -> IO [String]
getKnownServers cfg
......
......@@ -19,7 +19,8 @@ import Control.Monad (guard, mplus, when)
import Network.Hackage.CabalInstall.Types (ConfigFlags (..), OutputGen (..)
, TempFlags (..), ResolvedPackage (..))
import Network.Hackage.CabalInstall.Config (getKnownServers, selectValidConfigDir)
import Network.Hackage.CabalInstall.Config (defaultConfDir, defaultCacheDir, defaultPkgListDir,
getKnownServers, selectValidConfigDir)
import qualified Distribution.Simple.Configure as Configure (findProgram, configCompiler)
import Distribution.ParseUtils (showDependency)
......@@ -118,14 +119,21 @@ mkConfigFlags cfg
prefix <- if tempUserIns cfg || tempUser cfg
then fmap Just (maybe localPrefix return (tempPrefix cfg))
else return Nothing
confPath <- selectValidConfigDir ( maybe id (:) (tempConfPath cfg)
["/etc/cabal-install"
,localConfig] )
when (tempVerbose cfg > 0) $ printf "Using config dir: %s\n" confPath
confDir <- selectValidConfigDir ( maybe id (:) (tempConfDir cfg)
[defaultConfDir, localConfig] )
-- FIXME: put these in the user dir if it's a user installation
let cacheDir = fromMaybe defaultCacheDir (tempCacheDir cfg)
let pkgListDir = fromMaybe defaultPkgListDir (tempPkgListDir cfg)
when (tempVerbose cfg > 0) $ do printf "Using config dir: %s\n" confDir
printf "Using cache dir: %s\n" cacheDir
printf "Using pkglist dir: %s\n" pkgListDir
outputGen <- defaultOutputGen (tempVerbose cfg)
let config = ConfigFlags
{ configCompiler = comp
, configConfPath = confPath
, configConfDir = confDir
-- FIXME: put it in the user dir if it's a user isntallation
, configCacheDir = cacheDir
, configPkgListDir = pkgListDir
, configPrefix = prefix
, configServers = []
, configTarPath = tarProg
......
......@@ -32,7 +32,7 @@ import Text.Printf (printf)
import System.Directory (doesFileExist, createDirectoryIfMissing)
import Network.Hackage.CabalInstall.Types (ConfigFlags (..), OutputGen (..), UnresolvedDependency (..))
import Network.Hackage.CabalInstall.Config (packagesDirectoryName)
import Network.Hackage.CabalInstall.Config (packagesDirectory)
import Network.Hackage.CabalInstall.Dependency (filterFetchables, resolveDependencies)
import Distribution.Package (PackageIdentifier, showPackageId)
......@@ -86,7 +86,7 @@ downloadPackage cfg pkg url
case mbError of
Just err -> fail $ printf "Failed to download '%s': %s" (showPackageId pkg) (show err)
Nothing -> return path
where path = configConfPath cfg `joinFileName` packagesDirectoryName `joinFileName` showPackageId pkg
where path = packageFile cfg pkg
-- Downloads an index file to [config-dir/packages/serv-id
downloadIndex :: ConfigFlags -> String -> IO String
......@@ -99,10 +99,6 @@ downloadIndex cfg serv
where url = serv ++ "/" ++ "00-index.tar.gz"
path = packagesDirectory cfg `joinFileName` "00-index" `joinFileExt` "tar.gz"
-- |Full path to the packages directory.
packagesDirectory :: ConfigFlags -> FilePath
packagesDirectory cfg = configConfPath cfg `joinFileName` packagesDirectoryName
-- |Generate the full path to a given @PackageIdentifer@.
packageFile :: ConfigFlags -> PackageIdentifier -> FilePath
packageFile cfg pkg = packagesDirectory cfg `joinFileName` (showPackageId pkg)
......
......@@ -25,6 +25,7 @@ import System.Console.GetOpt (ArgDescr (..), ArgOrder (..), OptDescr (..), usage
import System.Exit (exitWith, ExitCode (..))
import System.Environment (getProgName)
import Network.Hackage.CabalInstall.Config (defaultConfDir, defaultCacheDir, defaultPkgListDir)
import Network.Hackage.CabalInstall.Types (TempFlags (..), Flag (..), Action (..)
, UnresolvedDependency (..))
......@@ -32,7 +33,9 @@ emptyTempFlags :: TempFlags
emptyTempFlags = TempFlags {
tempHcFlavor = defaultCompilerFlavor, -- Nothing,
tempHcPath = Nothing,
tempConfPath = Nothing,
tempConfDir = Nothing,
tempCacheDir = Nothing,
tempPkgListDir = Nothing,
tempHcPkg = Nothing,
tempPrefix = Nothing,
tempServers = [],
......@@ -59,8 +62,12 @@ globalOptions =
, Option "" ["hugs"] (NoArg HugsFlag) "compile with hugs"
, Option "s" ["with-server"] (ReqArg WithServer "URL")
"give the URL to a Hackage server"
, Option "c" ["config-path"] (ReqArg WithConfPath "PATH")
"give the path to the config dir. Default is /etc/cabal-install"
, Option "c" ["config-dir"] (ReqArg WithConfDir "PATH")
("give the path to the config dir. Default is " ++ defaultConfDir)
, Option "" ["cache-dir"] (ReqArg WithCacheDir "PATH")
("give the path to the package cache dir. Default is " ++ defaultCacheDir)
, Option "" ["pkglist-dir"] (ReqArg WithPkgListDir "PATH")
("give the path to the package list dir. Default is " ++ defaultPkgListDir)
, Option "" ["tar-path"] (ReqArg WithTarPath "PATH")
"give the path to tar"
, Option "w" ["with-compiler"] (ReqArg WithCompiler "PATH")
......@@ -145,7 +152,9 @@ mkTempFlags = updateCfg
NhcFlag -> t { tempHcFlavor = Just NHC }
HugsFlag -> t { tempHcFlavor = Just Hugs }
WithCompiler path -> t { tempHcPath = Just path }
WithConfPath path -> t { tempConfPath = Just path }
WithConfDir path -> t { tempConfDir = Just path }
WithCacheDir path -> t { tempCacheDir = Just path }
WithPkgListDir path -> t { tempPkgListDir = Just path }
WithHcPkg path -> t { tempHcPkg = Just path }
WithServer url -> t { tempServers = url:tempServers t }
Verbose n -> t { tempVerbose = n }
......
......@@ -40,7 +40,9 @@ data Action
data TempFlags = TempFlags {
tempHcFlavor :: Maybe CompilerFlavor,
tempHcPath :: Maybe FilePath, -- ^given compiler location
tempConfPath :: Maybe FilePath,
tempConfDir :: Maybe FilePath,
tempCacheDir :: Maybe FilePath,
tempPkgListDir :: Maybe FilePath,
tempHcPkg :: Maybe FilePath, -- ^given hc-pkg location
tempPrefix :: Maybe FilePath,
tempServers :: [String], -- ^Available Hackage servers.
......@@ -54,7 +56,9 @@ data TempFlags = TempFlags {
data ConfigFlags = ConfigFlags {
configCompiler :: Compiler,
configConfPath :: FilePath,
configConfDir :: FilePath,
configCacheDir :: FilePath,
configPkgListDir :: FilePath,
configPrefix :: Maybe FilePath,
configServers :: [String], -- ^Available Hackage servers.
configTarPath :: FilePath,
......@@ -68,7 +72,8 @@ data ConfigFlags = ConfigFlags {
data Flag
= GhcFlag | NhcFlag | HugsFlag
| WithCompiler FilePath | WithHcPkg FilePath
| WithConfPath FilePath | WithTarPath FilePath
| WithConfDir FilePath | WithCacheDir FilePath | WithPkgListDir FilePath
| WithTarPath FilePath
| WithServer String
| UserFlag | GlobalFlag
| UserInstallFlag | GlobalInstallFlag
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment