From 1522d270077abad43a6d8d7fea2bd8163ed912fd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 17 Jul 2017 12:51:40 -0400 Subject: Propellor.Property.LightDM.autoLogin: Made revertable. * Propellor.Property.LightDM.autoLogin: Made revertable. (minor API change) * Propellor.Property.Conffile: Added lacksIniSetting. This commit was sponsored by Jack Hill on Patreon. --- src/Propellor/Property/ConfFile.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/Propellor/Property/ConfFile.hs') diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index ce092ec9..76d52bd9 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -9,6 +9,7 @@ module Propellor.Property.ConfFile ( IniSection, IniKey, containsIniSetting, + lacksIniSetting, hasIniSection, lacksIniSection, iniFileContains, @@ -93,6 +94,19 @@ containsIniSetting f (header, key, value) = adjustIniSection go (l:ls) = if isKeyVal l then confline : ls else l : go ls isKeyVal x = (filter (/= ' ') . takeWhile (/= '=')) x `elem` [key, '#':key] +-- | Removes a key=value setting from a section of an .ini file. +-- Note that the section heading is left in the file, so this is not a +-- perfect reversion of containsIniSetting. +lacksIniSetting :: FilePath -> (IniSection, IniKey, String) -> Property UnixLike +lacksIniSetting f (header, key, value) = adjustIniSection + (f ++ " section [" ++ header ++ "] lacks " ++ key ++ "=" ++ value) + header + (filter (/= confline)) + id + f + where + confline = key ++ "=" ++ value + -- | Ensures that a .ini file exists and contains a section -- with a given key=value list of settings. hasIniSection :: FilePath -> IniSection -> [(IniKey, String)] -> Property UnixLike -- cgit v1.2.3