From 57b084713497bf16a59cc0769148bfad7c7cea71 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 20 Nov 2017 14:32:40 -0700 Subject: prevent Sbuilt.useHostProxy from looping by not peeking too early --- src/Propellor/Property/Apt.hs | 12 ++++++++---- src/Propellor/Property/Sbuild.hs | 13 ++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src/Propellor/Property') diff --git a/src/Propellor/Property/Apt.hs b/src/Propellor/Property/Apt.hs index 68ebe89e..d44b5c38 100644 --- a/src/Propellor/Property/Apt.hs +++ b/src/Propellor/Property/Apt.hs @@ -501,12 +501,16 @@ dpkgStatus = "/var/lib/dpkg/status" -- | Set apt's proxy proxy :: Url -> Property (HasInfo + DebianLike) -proxy u = tightenTargets $ - proxyInfo `before` proxyConfig `describe` desc +proxy u = setInfoProperty (proxy' u) (proxyInfo u) where - proxyInfo = pureInfoProperty desc (InfoVal (HostAptProxy u)) - proxyConfig = "/etc/apt/apt.conf.d/20proxy" `File.hasContent` + proxyInfo = toInfo . InfoVal . HostAptProxy + +proxy' :: Url -> Property DebianLike +proxy' u = tightenTargets $ + "/etc/apt/apt.conf.d/20proxy" `File.hasContent` [ "Acquire::HTTP::Proxy \"" ++ u ++ "\";" ] + `describe` desc + where desc = (u ++ " apt proxy selected") -- | Cause apt to proxy downloads via an apt cacher on localhost diff --git a/src/Propellor/Property/Sbuild.hs b/src/Propellor/Property/Sbuild.hs index f884b352..d323ee67 100644 --- a/src/Propellor/Property/Sbuild.hs +++ b/src/Propellor/Property/Sbuild.hs @@ -252,12 +252,15 @@ update = Apt.update `before` Apt.upgrade `before` Apt.autoRemove -- | Ensure that an sbuild schroot uses the host's Apt proxy. -- -- This property is standardly used when the host has 'Apt.useLocalCacher'. -useHostProxy :: Host -> Property (HasInfo + DebianLike) -useHostProxy h = case getProxyInfo of - Nothing -> doNothing - Just (Apt.HostAptProxy u) -> Apt.proxy u +useHostProxy :: Host -> Property DebianLike +useHostProxy h = property' "use host's apt proxy" $ \w -> + -- Note that we can't look at getProxyInfo outside the property, + -- as that would loop, but it's ok to look at it inside the + -- property. Thus the slightly strange construction here. + case getProxyInfo of + Just (Apt.HostAptProxy u) -> ensureProperty w (Apt.proxy' u) + Nothing -> noChange where - getProxyInfo :: Maybe Apt.HostAptProxy getProxyInfo = fromInfoVal . fromInfo . hostInfo $ h aptCacheLine :: String -- cgit v1.2.3