diff options
Diffstat (limited to 'src/Propellor')
| -rw-r--r-- | src/Propellor/Property/ConfFile.hs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index 270e04f1..d91c7724 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -9,6 +9,7 @@ module Propellor.Property.ConfFile ( IniSection, IniKey, containsIniSetting, + hasIniSection, lacksIniSection, ) where @@ -24,7 +25,7 @@ type SectionStart = Line -> Bool type SectionPast = Line -> Bool -- | run on all lines in the section, including the SectionStart line; -- can add, delete, and modify lines, or even delete entire section -type AdjustSection = [Line] -> [Line] +type AdjustSection = [Line] -> [Line] -- | if SectionStart does not find the section in the file, this is used to -- insert the section somewhere within it type InsertSection = [Line] -> [Line] @@ -92,6 +93,21 @@ containsIniSetting f (header, key, value) = go (l:ls) = if isKeyVal l then confline : ls else l : (go ls) isKeyVal x = (filter (/= ' ') . takeWhile (/= '=')) x `elem` [key, '#':key] +-- | 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 +hasIniSection f header keyvalues = + adjustIniSection + ("set " ++ f ++ " section [" ++ header ++ "]") + header + go + (++ [confheader] ++ conflines) -- add missing section at end + f + where + confheader = iniHeader header + conflines = map (\(key, value) -> key ++ "=" ++ value) keyvalues + go _ = conflines + -- | Ensures that a .ini file does not contain the specified section. lacksIniSection :: FilePath -> IniSection -> Property UnixLike lacksIniSection f header = |
