From 0ee04ecc43e047b00437fb660e71f7dd67dd3afc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 24 Jan 2015 22:38:10 -0400 Subject: GADT properties seem to work (untested) * Property has been converted to a GADT, and will be Property NoInfo or Property HasInfo. This was done to make sure that ensureProperty is only used on properties that do not have Info. Transition guide: - Change all "Property" to "Property NoInfo" or "Property WithInfo" (The compiler can tell you if you got it wrong!) - To construct a RevertableProperty, it is useful to use the new () operator - Constructing a list of properties can be problimatic, since Property NoInto and Property WithInfo are different types and cannot appear in the same list. To deal with this, "props" has been added, and can built up a list of properties of different types, using the same (&) and (!) operators that are used to build up a host's properties. --- src/Propellor/Property/Chroot.hs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/Propellor/Property/Chroot.hs') diff --git a/src/Propellor/Property/Chroot.hs b/src/Propellor/Property/Chroot.hs index 0ef6e7dd..e56cb6ed 100644 --- a/src/Propellor/Property/Chroot.hs +++ b/src/Propellor/Property/Chroot.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE FlexibleContexts #-} + module Propellor.Property.Chroot ( Chroot(..), BuilderConf(..), @@ -59,12 +61,13 @@ debootstrapped system conf location = case system of provisioned :: Chroot -> RevertableProperty provisioned c = provisioned' (propigateChrootInfo c) c False -provisioned' :: (Property -> Property) -> Chroot -> Bool -> RevertableProperty -provisioned' propigator c@(Chroot loc system builderconf _) systemdonly = RevertableProperty +provisioned' :: (Property HasInfo -> Property HasInfo) -> Chroot -> Bool -> RevertableProperty +provisioned' propigator c@(Chroot loc system builderconf _) systemdonly = (propigator $ go "exists" setup) + (go "removed" teardown) where - go desc a = property (chrootDesc c desc) $ ensureProperties [a] + go desc a = propertyList (chrootDesc c desc) [a] setup = propellChroot c (inChrootProcess c) systemdonly `requires` toProp built @@ -77,10 +80,10 @@ provisioned' propigator c@(Chroot loc system builderconf _) systemdonly = Revert teardown = toProp (revert built) -propigateChrootInfo :: Chroot -> Property -> Property +propigateChrootInfo :: (IsProp (Property i)) => Chroot -> Property i -> Property HasInfo propigateChrootInfo c p = propigateContainer c p' where - p' = mkProperty + p' = infoProperty (propertyDesc p) (propertySatisfy p) (propertyInfo p <> chrootInfo c) @@ -91,7 +94,7 @@ chrootInfo (Chroot loc _ _ h) = mempty { _chrootinfo = mempty { _chroots = M.singleton loc h } } -- | Propellor is run inside the chroot to provision it. -propellChroot :: Chroot -> ([String] -> CreateProcess) -> Bool -> Property +propellChroot :: Chroot -> ([String] -> CreateProcess) -> Bool -> Property NoInfo propellChroot c@(Chroot loc _ _ _) mkproc systemdonly = property (chrootDesc c "provisioned") $ do let d = localdir shimdir c let me = localdir "propellor" @@ -148,7 +151,8 @@ chain hostlist (ChrootChain hn loc systemdonly onconsole) = r <- runPropellor h $ ensureProperties $ if systemdonly then [Systemd.installed] - else hostProperties h + else map ignoreInfo $ + hostProperties h putStrLn $ "\n" ++ show r chain _ _ = errorMessage "bad chain command" -- cgit v1.3-2-g0d8e