summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/File.hs
diff options
context:
space:
mode:
authorPer Olofsson2015-10-23 15:54:39 +0200
committerJoey Hess2015-10-23 13:37:44 -0400
commitacb7ad7a925b8597af42158d52544aebf89abb0e (patch)
treee5ca3e5e9af56133e4feb2aa78cb13ac22428961 /src/Propellor/Property/File.hs
parenta6790167e9ee14d818a88e3f8164cfd7608ec2d5 (diff)
Add File.basedOn
Signed-off-by: Per Olofsson <pelle@dsv.su.se>
Diffstat (limited to 'src/Propellor/Property/File.hs')
-rw-r--r--src/Propellor/Property/File.hs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/Propellor/Property/File.hs b/src/Propellor/Property/File.hs
index 7e421cb7..3476bad0 100644
--- a/src/Propellor/Property/File.hs
+++ b/src/Propellor/Property/File.hs
@@ -70,6 +70,13 @@ f `lacksLine` l = fileProperty (f ++ " remove: " ++ l) (filter (/= l)) f
lacksLines :: FilePath -> [Line] -> Property NoInfo
f `lacksLines` ls = fileProperty (f ++ " remove: " ++ show [ls]) (filter (`notElem` ls)) f
+-- | Replaces the content of a file with the transformed content of another file
+basedOn :: FilePath -> (FilePath, [Line] -> [Line]) -> Property NoInfo
+f `basedOn` (f', a) = property desc $ go =<< (liftIO $ readFile f')
+ where
+ desc = "replace " ++ f
+ go tmpl = ensureProperty $ fileProperty desc (\_ -> a $ lines $ tmpl) f
+
-- | Removes a file. Does not remove symlinks or non-plain-files.
notPresent :: FilePath -> Property NoInfo
notPresent f = check (doesFileExist f) $ property (f ++ " not present") $