summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-02 23:34:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-03 00:56:01 -0400
commitdd7686057df90767be90d86887511350a98574d1 (patch)
treec06244861182274875d11814435c66b01c0260c2 /Utility
parent457a6a0b40fad3146093c73c5f3d58d4b04d0cd2 (diff)
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.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/FileMode.hs11
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