diff options
| author | Félix Sipma <felix.sipma@no-log.org> | 2016-06-20 18:18:01 +0200 |
|---|---|---|
| committer | Félix Sipma <felix.sipma@no-log.org> | 2016-06-20 18:18:01 +0200 |
| commit | 57795f70061e05d6cd47e7363c021bc0b5d4e9ae (patch) | |
| tree | 396c387ed87379da17e4241c78bfed765bc09dc0 | |
| parent | d545ca394d423dab2f3c04b28adaca48ed04bf27 (diff) | |
ConfFile: cosmetic fixes
| -rw-r--r-- | src/Propellor/Property/ConfFile.hs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index 54762689..b49c626e 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -44,7 +44,7 @@ adjustSection desc start past adjust insert = fileProperty desc go go ls = let (pre, wanted, post) = foldl' find ([], [], []) ls in if null wanted then insert ls - else pre ++ (adjust wanted) ++ post + else pre ++ adjust wanted ++ post find (pre, wanted, post) l | null wanted && null post && (not . start) l = (pre ++ [l], wanted, post) @@ -79,8 +79,7 @@ adjustIniSection desc header = -- | Ensures that a .ini file exists and contains a section -- with a key=value setting. containsIniSetting :: FilePath -> (IniSection, IniKey, String) -> Property UnixLike -containsIniSetting f (header, key, value) = - adjustIniSection +containsIniSetting f (header, key, value) = adjustIniSection (f ++ " section [" ++ header ++ "] contains " ++ key ++ "=" ++ value) header go @@ -90,28 +89,26 @@ containsIniSetting f (header, key, value) = confheader = iniHeader header confline = key ++ "=" ++ value go [] = [confline] - go (l:ls) = if isKeyVal l then confline : ls else l : (go ls) + 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 +hasIniSection f header keyvalues = adjustIniSection ("set " ++ f ++ " section [" ++ header ++ "]") header go - (++ [confheader] ++ conflines) -- add missing section at end + (++ confheader : conflines) -- add missing section at end f where confheader = iniHeader header conflines = map (\(key, value) -> key ++ "=" ++ value) keyvalues - go _ = [confheader] ++ conflines + go _ = confheader : conflines -- | Ensures that a .ini file does not contain the specified section. lacksIniSection :: FilePath -> IniSection -> Property UnixLike -lacksIniSection f header = - adjustIniSection +lacksIniSection f header = adjustIniSection (f ++ " lacks section [" ++ header ++ "]") header (const []) -- remove all lines of section |
