Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update multiple remote-repos in parallel #2503

Merged
merged 3 commits into from Mar 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/IndexUtils.hs
Expand Up @@ -391,7 +391,7 @@ parsePreferredVersions = mapMaybe simpleParse

updatePackageIndexCacheFile :: Verbosity -> FilePath -> FilePath -> IO ()
updatePackageIndexCacheFile verbosity indexFile cacheFile = do
info verbosity "Updating the index cache file..."
info verbosity ("Updating index cache file " ++ cacheFile)
(mkPkgs, prefs) <- either fail return
. parsePackageIndex
. maybeDecompress
Expand Down
18 changes: 15 additions & 3 deletions cabal-install/Distribution/Client/Update.hs
Expand Up @@ -22,6 +22,8 @@ import Distribution.Client.FetchUtils
( downloadIndex )
import Distribution.Client.IndexUtils
( updateRepoIndexCache )
import Distribution.Client.JobControl
( newParallelJobControl, spawnJob, collectJob )

import Distribution.Simple.Utils
( writeFileAtomic, warn, notice )
Expand All @@ -31,21 +33,31 @@ import Distribution.Verbosity
import qualified Data.ByteString.Lazy as BS
import Distribution.Client.GZipUtils (maybeDecompress)
import System.FilePath (dropExtension)
import Data.Either (lefts)

-- | 'update' downloads the package list from all known servers
update :: Verbosity -> [Repo] -> IO ()
update verbosity [] =
warn verbosity $ "No remote package servers have been specified. Usually "
++ "you would have one specified in the config file."
update verbosity repos = do
mapM_ (updateRepo verbosity) repos
jobCtrl <- newParallelJobControl
let remoteRepos = lefts (map repoKind repos)
case remoteRepos of
[] -> return ()
[remoteRepo] ->
notice verbosity $ "Downloading the latest package list from "
++ remoteRepoName remoteRepo
_ -> notice verbosity . unlines
$ "Downloading the latest package lists from: "
: map (("- " ++) . remoteRepoName) remoteRepos
mapM_ (spawnJob jobCtrl . updateRepo verbosity) repos
mapM_ (\_ -> collectJob jobCtrl) repos

updateRepo :: Verbosity -> Repo -> IO ()
updateRepo verbosity repo = case repoKind repo of
Right LocalRepo -> return ()
Left remoteRepo -> do
notice verbosity $ "Downloading the latest package list from "
++ remoteRepoName remoteRepo
downloadResult <- downloadIndex verbosity remoteRepo (repoLocalDir repo)
case downloadResult of
FileAlreadyInCache -> return ()
Expand Down