From acb7ad7a925b8597af42158d52544aebf89abb0e Mon Sep 17 00:00:00 2001 From: Per Olofsson Date: Fri, 23 Oct 2015 15:54:39 +0200 Subject: Add File.basedOn Signed-off-by: Per Olofsson --- src/Propellor/Property/File.hs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/Propellor/Property/File.hs') 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") $ -- cgit v1.2.3