From cfb758d655ec9e825cfd25c233c2c55589324236 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 17 Jul 2014 22:35:59 -0400 Subject: better hasPrivContentExposed Avoid locking down and then lossening the file mode; just use the default/current mode from the beginning. --- src/Propellor/Property/File.hs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/Propellor/Property/File.hs') diff --git a/src/Propellor/Property/File.hs b/src/Propellor/Property/File.hs index 0e738f25..07ac8c26 100644 --- a/src/Propellor/Property/File.hs +++ b/src/Propellor/Property/File.hs @@ -18,17 +18,23 @@ f `hasContent` newcontent = fileProperty ("replace " ++ f) -- The file's permissions are preserved if the file already existed. -- Otherwise, they're set to 600. hasPrivContent :: FilePath -> Context -> Property -hasPrivContent f context = withPrivData (PrivFile f) context $ \getcontent -> - property desc $ getcontent $ \privcontent -> - ensureProperty $ fileProperty' writeFileProtected desc - (\_oldcontent -> lines privcontent) f - where - desc = "privcontent " ++ f +hasPrivContent = hasPrivContent' writeFileProtected --- | Leaves the file world-readable. +-- | Leaves the file at its default or current mode, +-- allowing "private" data to be read. +-- +-- Use with caution! hasPrivContentExposed :: FilePath -> Context -> Property -hasPrivContentExposed f context = hasPrivContent f context `onChange` - mode f (combineModes (ownerWriteMode:readModes)) +hasPrivContentExposed = hasPrivContent' writeFile + +hasPrivContent' :: (String -> FilePath -> IO ()) -> FilePath -> Context -> Property +hasPrivContent' writer f context = + withPrivData (PrivFile f) context $ \getcontent -> + property desc $ getcontent $ \privcontent -> + ensureProperty $ fileProperty' writer desc + (\_oldcontent -> lines privcontent) f + where + desc = "privcontent " ++ f -- | Ensures that a line is present in a file, adding it to the end if not. containsLine :: FilePath -> Line -> Property -- cgit v1.3-2-g0d8e From 55a638ad4c7605041ece96843a1d608d40c2984d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 17 Jul 2014 23:32:29 -0400 Subject: Fix bug in File.containsLines that caused lines that were already in the file to sometimes be appended to the end. --- debian/changelog | 7 +++++++ src/Propellor/Property/File.hs | 6 ++---- src/Propellor/Property/SiteSpecific/JoeySites.hs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src/Propellor/Property/File.hs') diff --git a/debian/changelog b/debian/changelog index 54923662..5e5460e3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +propellor (0.8.2) UNRELEASED; urgency=medium + + * Fix bug in File.containsLines that caused lines that were already in the + file to sometimes be appended to the end. + + -- Joey Hess Thu, 17 Jul 2014 23:32:01 -0400 + propellor (0.8.1) unstable; urgency=medium * Run apt-get update in initial bootstrap. diff --git a/src/Propellor/Property/File.hs b/src/Propellor/Property/File.hs index 07ac8c26..bc499e07 100644 --- a/src/Propellor/Property/File.hs +++ b/src/Propellor/Property/File.hs @@ -41,11 +41,9 @@ containsLine :: FilePath -> Line -> Property f `containsLine` l = f `containsLines` [l] containsLines :: FilePath -> [Line] -> Property -f `containsLines` l = fileProperty (f ++ " contains:" ++ show l) go f +f `containsLines` ls = fileProperty (f ++ " contains:" ++ show ls) go f where - go ls - | all (`elem` ls) l = ls - | otherwise = ls++l + go content = content ++ filter (`notElem` content) ls -- | Ensures that a line is not present in a file. -- Note that the file is ensured to exist, so if it doesn't, an empty diff --git a/src/Propellor/Property/SiteSpecific/JoeySites.hs b/src/Propellor/Property/SiteSpecific/JoeySites.hs index e00c3191..a4d335e3 100644 --- a/src/Propellor/Property/SiteSpecific/JoeySites.hs +++ b/src/Propellor/Property/SiteSpecific/JoeySites.hs @@ -465,7 +465,7 @@ kiteMailServer = propertyList "kitenet.net mail server" , "smtp_use_tls = yes" , "smtp_tls_session_cache_database = sdbm:/etc/postfix/smtp_scache" ] - -- `onChange` Postfix.dedupMainCf + `onChange` Postfix.dedupMainCf `onChange` Service.restarted "postfix" `describe` "postfix configured" , Apt.serviceInstalledRunning "dovecot-imapd" -- cgit v1.3-2-g0d8e