summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2016-06-20 13:52:00 -0400
committerJoey Hess2016-06-20 13:52:00 -0400
commit26634f935be7d748f86314c1e05eb8957a72b3a5 (patch)
tree0cd0da04d2665ed470ed217b0fac256399e16fab /src
parenta0d9ebf0334c98be75d18fd83d860ec7370a8005 (diff)
parent57795f70061e05d6cd47e7363c021bc0b5d4e9ae (diff)
Merge remote-tracking branch 'felix/hasinisection-header'
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/ConfFile.hs17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs
index d91c7724..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 _ = 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