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

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/09ea8356f68c31ed5d2f32fb331e5b900c98b334

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

commit 09ea8356f68c31ed5d2f32fb331e5b900c98b334
Author: Duncan Coutts <[email protected]>
Date:   Wed May 7 00:10:06 2008 +0000

    Add lookupConfiguredPackage helper function to InstallPlan
    Simplifies implementation of completed and failed

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

 cabal-install/Hackage/InstallPlan.hs |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/cabal-install/Hackage/InstallPlan.hs 
b/cabal-install/Hackage/InstallPlan.hs
index e715fed..0f883c0 100644
--- a/cabal-install/Hackage/InstallPlan.hs
+++ b/cabal-install/Hackage/InstallPlan.hs
@@ -232,10 +232,9 @@ next plan@(InstallPlan { planIndex = index }) = assert 
(invariant plan) $
 completed :: PackageIdentifier
           -> InstallPlan buildResult -> InstallPlan buildResult
 completed pkgid plan =
-  case PackageIndex.lookupPackageId index pkgid of
-    Just (Configured cp) -> plan { planIndex = PackageIndex.insert (Installed 
cp) index }
-    _ -> error "InstallPlan.completed: internal error; cannot mark package as 
completed"
-  where index = planIndex plan
+  plan { planIndex = PackageIndex.insert installed (planIndex plan) }
+  where
+    installed = Installed (lookupConfiguredPackage plan pkgid)
 
 -- | Marks a package in the graph as having failed. It also marks all the
 -- packages that depended on it as having failed.
@@ -268,6 +267,16 @@ failed pkgid buildResult dependentBuildResult
         in foldr markDepsAsFailed index'' deps
       _ -> index'
 
+-- | lookup a package that we expect to be in the configured state
+--
+lookupConfiguredPackage :: InstallPlan a
+                        -> PackageIdentifier -> ConfiguredPackage
+lookupConfiguredPackage plan pkgid =
+  case PackageIndex.lookupPackageId (planIndex plan) pkgid of
+    Just (Configured pkg) -> pkg
+    Just _  -> error $ "InstallPlan: not configured " ++ display pkgid
+    Nothing -> error $ "InstallPlan: no such package " ++ display pkgid
+
 -- ------------------------------------------------------------
 -- * Checking valididy of plans
 -- ------------------------------------------------------------



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

Reply via email to