From 57795f70061e05d6cd47e7363c021bc0b5d4e9ae Mon Sep 17 00:00:00 2001 From: FĂ©lix Sipma Date: Mon, 20 Jun 2016 18:18:01 +0200 Subject: ConfFile: cosmetic fixes --- src/Propellor/Property/ConfFile.hs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/Propellor/Property/ConfFile.hs') 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 -- cgit v1.2.3