From dd7686057df90767be90d86887511350a98574d1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 2 May 2013 23:34:58 -0400 Subject: avoid crashing on Android when file mode of .git/annex/url cannot be set Presumably, if the filesystem doesn't support file permissions, it's not much of a multiuser system. --- Utility/FileMode.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'Utility/FileMode.hs') 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 -- cgit v1.2.3