summaryrefslogtreecommitdiff
path: root/Propellor/Property/File.hs
diff options
context:
space:
mode:
authorJoey Hess2014-04-04 00:08:30 -0400
committerJoey Hess2014-04-04 00:08:30 -0400
commitcf3fc9b8e9a9e93c6784f78e0ba48f518d3003f7 (patch)
treecf32fb5ebbb5d816df8974616df77f7b4dba2384 /Propellor/Property/File.hs
parentd19171ed53884c0422b27ccc6aac4960c96ccc7d (diff)
fix file mode bug
Diffstat (limited to 'Propellor/Property/File.hs')
-rw-r--r--Propellor/Property/File.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/Propellor/Property/File.hs b/Propellor/Property/File.hs
index af4f554f..80c69d9b 100644
--- a/Propellor/Property/File.hs
+++ b/Propellor/Property/File.hs
@@ -2,6 +2,8 @@ module Propellor.Property.File where
import Propellor
+import System.Posix.Files
+
type Line = String
-- | Replaces all the content of a file.
@@ -32,13 +34,19 @@ fileProperty :: Desc -> ([Line] -> [Line]) -> FilePath -> Property
fileProperty desc a f = Property desc $ go =<< doesFileExist f
where
go True = do
- ls <- lines <$> catchDefaultIO [] (readFile f)
+ ls <- lines <$> readFile f
let ls' = a ls
if ls' == ls
then noChange
- else makeChange $ viaTmp writeFile f (unlines ls')
+ else makeChange $ viaTmp updatefile f (unlines ls')
go False = makeChange $ writeFile f (unlines $ a [])
+ -- viaTmp makes the temp file mode 600.
+ -- Replicate the original file mode before moving it into place.
+ updatefile f' content = do
+ writeFile f' content
+ getFileStatus f >>= setFileMode f' . fileMode
+
-- | Ensures a directory exists.
dirExists :: FilePath -> Property
dirExists d = check (not <$> doesDirectoryExist d) $ Property (d ++ " exists") $