diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-08-20 10:42:28 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-08-20 10:42:28 -0400 |
| commit | 26d4c13779ea22dfaffd87eea93660f4309e4b52 (patch) | |
| tree | 5cceed2f890b8d2c22f056501033cd10b2e27c11 /src/Propellor/Property | |
| parent | af64947bed028ac64cf12f7d355bc20d4f0b50a5 (diff) | |
| parent | bea60fc136a70bdcea3f7f2ace9c8f0e8a5c2dce (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Property')
| -rw-r--r-- | src/Propellor/Property/ConfFile.hs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index 1a2503dd..066848bb 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -9,6 +9,7 @@ module Propellor.Property.ConfFile ( IniSection, IniKey, containsIniSetting, + lacksIniSection, ) where import Propellor @@ -22,7 +23,7 @@ type SectionStart = Line -> Bool -- (eg, a new section header) type SectionPast = Line -> Bool -- | run on all lines in the section, including the SectionStart line; --- can add/delete/modify lines, or even delete entire section +-- can add, delete, and modify lines, or even delete entire section type AdjustSection = [Line] -> [Line] -- | if SectionStart does not find the section in the file, this is used to -- insert the section somewhere within it @@ -52,11 +53,11 @@ adjustSection desc start past adjust insert f = (pre, wanted ++ [l], post) | otherwise = (pre, wanted, post ++ [l]) --- | Name of a section of a Windows-style .ini file. This value is put +-- | Name of a section of an .ini file. This value is put -- in square braces to generate the section header. type IniSection = String --- | Name of a configuration setting within a Windows-style .init file. +-- | Name of a configuration setting within a .ini file. type IniKey = String iniHeader :: IniSection -> String @@ -75,7 +76,7 @@ adjustIniSection desc header = (== iniHeader header) ("[" `isPrefixOf`) --- | Ensures that a Windows-style .ini file exists and contains a section +-- | Ensures that a .ini file exists and contains a section -- with a key=value setting. containsIniSetting :: FilePath -> (IniSection, IniKey, String) -> Property NoInfo containsIniSetting f (header, key, value) = @@ -83,7 +84,7 @@ containsIniSetting f (header, key, value) = (f ++ " section [" ++ header ++ "] contains " ++ key ++ "=" ++ value) header go - (++ [confheader, confline]) + (++ [confheader, confline]) -- add missing section at end f where confheader = iniHeader header @@ -91,3 +92,13 @@ containsIniSetting f (header, key, value) = go [] = [confline] 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 does not contain the specified section. +lacksIniSection :: FilePath -> IniSection -> Property NoInfo +lacksIniSection f header = + adjustIniSection + (f ++ " lacks section [" ++ header ++ "]") + header + (const []) -- remove all lines of section + id -- add no lines if section is missing + f |
