summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/File.hs
diff options
context:
space:
mode:
authorJoey Hess2017-07-05 16:57:03 -0400
committerJoey Hess2017-07-05 16:57:03 -0400
commit0d15c3f01a424e021481c9630441997c032cbc82 (patch)
tree1f7c12ee3083bd1300f926c6bce53004efcf0bc7 /src/Propellor/Property/File.hs
parent256c5c3c572e56d3755914e40cfd9dfd94112bbb (diff)
Added File.checkOverwrite.
This commit was sponsored by Ethan Aubin.
Diffstat (limited to 'src/Propellor/Property/File.hs')
-rw-r--r--src/Propellor/Property/File.hs9
1 files changed, 9 insertions, 0 deletions
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)