Repository : ssh://darcs.haskell.org//srv/darcs/packages/Cabal

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/8e824e6f037991b28313e1b14ea34343c0423c88

>---------------------------------------------------------------

commit 8e824e6f037991b28313e1b14ea34343c0423c88
Author: Duncan Coutts <[email protected]>
Date:   Sun Feb 27 12:50:08 2011 +0000

    Partial fix for handling multiple installed instances of same package 
version
    Previously when multiple instances of the same package are installed,
    e.g. in global and user dbs, we would often end up selecting the wrong
    instance. Now we select the user one consistently which will solve the
    problem in most (but not all) cases.

>---------------------------------------------------------------

 cabal-install/Distribution/Client/IndexUtils.hs |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/cabal-install/Distribution/Client/IndexUtils.hs 
b/cabal-install/Distribution/Client/IndexUtils.hs
index c2cec77..4088ade 100644
--- a/cabal-install/Distribution/Client/IndexUtils.hs
+++ b/cabal-install/Distribution/Client/IndexUtils.hs
@@ -22,7 +22,8 @@ import qualified Distribution.Client.Tar as Tar
 import Distribution.Client.Types
 
 import Distribution.Package
-         ( PackageId, PackageIdentifier(..), PackageName(..), Package(..)
+         ( PackageId, PackageIdentifier(..), PackageName(..)
+         , Package(..), packageVersion
          , Dependency(Dependency), InstalledPackageId(..) )
 import Distribution.Client.PackageIndex (PackageIndex)
 import qualified Distribution.Client.PackageIndex as PackageIndex
@@ -47,10 +48,10 @@ import Distribution.Text
 import Distribution.Verbosity
          ( Verbosity, lessVerbose )
 import Distribution.Simple.Utils
-         ( warn, info, fromUTF8 )
+         ( warn, info, fromUTF8, equating )
 
 import Data.Maybe  (catMaybes, fromMaybe)
-import Data.List   (isPrefixOf)
+import Data.List   (isPrefixOf, groupBy)
 import Data.Monoid (Monoid(..))
 import qualified Data.Map as Map
 import Control.Monad (MonadPlus(mplus), when)
@@ -79,13 +80,16 @@ getInstalledPackages verbosity comp packageDbs conf =
     verbosity'  = lessVerbose verbosity
 
     convert :: InstalledPackageIndex.PackageIndex -> PackageIndex 
InstalledPackage
-    convert index = PackageIndex.fromList $
-      reverse -- because later ones mask earlier ones, but
-              -- InstalledPackageIndex.allPackages gives us the most preferred
-              -- instances first, when packages share a package id, like when
-              -- the same package is installed in the global & user dbs.
+    convert index = PackageIndex.fromList
+      -- There can be multiple installed instances of each package version,
+      -- like when the same package is installed in the global & user dbs.
+      -- InstalledPackageIndex.allPackagesByName gives us the installed
+      -- packages with the most preferred instances first, so by picking the
+      -- first we should get the user one. This is almost but not quite the
+      -- same as what ghc does.
       [ InstalledPackage ipkg (sourceDeps index ipkg)
-      | ipkg <- InstalledPackageIndex.allPackages index ]
+      | ipkgs <- InstalledPackageIndex.allPackagesByName index
+      , (ipkg:_) <- groupBy (equating packageVersion) ipkgs ]
 
     -- The InstalledPackageInfo only lists dependencies by the
     -- InstalledPackageId, which means we do not directly know the 
corresponding



_______________________________________________
Cvs-libraries mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-libraries

Reply via email to