diff options
| author | Joey Hess <joeyh@joeyh.name> | 2016-06-15 10:20:28 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2016-06-15 10:20:28 -0400 |
| commit | 495344b242f3dd67d6de2a500aa76e44c40d768d (patch) | |
| tree | f6bce87d13580569b628ed7938f15046c6ac8665 /src/Propellor/Property | |
| parent | 104ff934d792e20f84c92499ae55bba2b3ba96ca (diff) | |
| parent | bec62e2bbe61672c8dcecc3ff1e8fd8a389ac86c (diff) | |
Merge remote-tracking branch 'felix/hasinisection'
Diffstat (limited to 'src/Propellor/Property')
| -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 = |
