Commit 09ea8356 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add lookupConfiguredPackage helper function to InstallPlan

Simplifies implementation of completed and failed
parent 22929525
......@@ -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
-- ------------------------------------------------------------
......
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