diff options
Diffstat (limited to 'Utility/FileMode.hs')
-rw-r--r-- | Utility/FileMode.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs index 0f7046333..b6bb579b5 100644 --- a/Utility/FileMode.hs +++ b/Utility/FileMode.hs @@ -10,6 +10,7 @@ module Utility.FileMode where import Common import Control.Exception (bracket) +import Utility.Exception import System.Posix.Types import Foreign (complement) @@ -103,10 +104,16 @@ setSticky :: FilePath -> IO () setSticky f = modifyFileMode f $ addModes [stickyMode] {- Writes a file, ensuring that its modes do not allow it to be read - - by anyone other than the current user, before any content is written. -} + - by anyone other than the current user, before any content is written. + - + - On a filesystem that does not support file permissions, this is the same + - as writeFile. + -} writeFileProtected :: FilePath -> String -> IO () writeFileProtected file content = do h <- openFile file WriteMode - modifyFileMode file $ removeModes [groupReadMode, otherReadMode] + void $ tryIO $ + modifyFileMode file $ + removeModes [groupReadMode, otherReadMode] hPutStr h content hClose h |