more robust apt

This commit is contained in:
Joey Hess 2014-04-02 00:31:07 -04:00
parent 3a4a3ea409
commit 9161ecaac2
1 changed files with 11 additions and 2 deletions

View File

@ -78,7 +78,7 @@ upgrade = runApt ["-y", "dist-upgrade"]
type Package = String
installed :: [Package] -> Property
installed ps = check (isInstallable ps) go
installed ps = robustly $ check (isInstallable ps) go
`describe` (unwords $ "apt installed":ps)
where
go = runApt $ ["-y", "install"] ++ ps
@ -90,11 +90,20 @@ removed ps = check (or <$> isInstalled' ps) go
go = runApt $ ["-y", "remove"] ++ ps
buildDep :: [Package] -> Property
buildDep ps = check (isInstallable ps) go
buildDep ps = robustly go
`describe` (unwords $ "apt build-dep":ps)
where
go = runApt $ ["-y", "build-dep"] ++ ps
{- Package installation may fail becuse the archive has changed.
- Run an update in that case and retry. -}
robustly :: Property -> Property
robustly p = Property (propertyDesc p) $ do
r <- ensureProperty p
if r == FailedChange
then ensureProperty $ p `requires` update
else return r
isInstallable :: [Package] -> IO Bool
isInstallable ps = do
l <- isInstalled' ps