From 0d15c3f01a424e021481c9630441997c032cbc82 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 5 Jul 2017 16:57:03 -0400 Subject: Added File.checkOverwrite. This commit was sponsored by Ethan Aubin. --- src/Propellor/Property/File.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/Propellor/Property/File.hs') diff --git a/src/Propellor/Property/File.hs b/src/Propellor/Property/File.hs index 8d10b94c..3293599a 100644 --- a/src/Propellor/Property/File.hs +++ b/src/Propellor/Property/File.hs @@ -307,3 +307,12 @@ readConfigFileName = readish . unescape Nothing -> '_' : ns ++ unescape cs' Just n -> chr n : unescape cs' unescape (c:cs) = c : unescape cs + +data Overwrite = OverwriteExisting | PreserveExisting + +-- | When passed PreserveExisting, only ensures the property when the file +-- does not exist. +checkOverwrite :: Overwrite -> FilePath -> (FilePath -> Property i) -> Property i +checkOverwrite OverwriteExisting f mkp = mkp f +checkOverwrite PreserveExisting f mkp = + check (not <$> doesFileExist f) (mkp f) -- cgit v1.3-2-g0d8e