diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-04-29 14:59:49 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-04-29 14:59:49 -0400 |
commit | 36852d90bc18cb7b2bddb1ce9dce39cc1f0203de (patch) | |
tree | 0419a1d67f6bb9db4ce79f8cb76b53752e2d7371 /Utility/FileMode.hs | |
parent | efe7e174bfab4d0dd2e88e7b6eb859940b2228ea (diff) | |
download | git-repair-36852d90bc18cb7b2bddb1ce9dce39cc1f0203de.tar.gz |
Merge from git-annex.
Diffstat (limited to 'Utility/FileMode.hs')
-rw-r--r-- | Utility/FileMode.hs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs index 832250b..201b845 100644 --- a/Utility/FileMode.hs +++ b/Utility/FileMode.hs @@ -1,6 +1,6 @@ {- File mode utilities. - - - Copyright 2010-2012 Joey Hess <joey@kitenet.net> + - Copyright 2010-2012 Joey Hess <id@joeyh.name> - - License: BSD-2-clause -} @@ -124,7 +124,7 @@ withUmask _ a = a #endif combineModes :: [FileMode] -> FileMode -combineModes [] = undefined +combineModes [] = 0 combineModes [m] = m combineModes (m:ms) = foldl unionFileModes m ms @@ -151,7 +151,11 @@ setSticky f = modifyFileMode f $ addModes [stickyMode] - as writeFile. -} writeFileProtected :: FilePath -> String -> IO () -writeFileProtected file content = withUmask 0o0077 $ +writeFileProtected file content = writeFileProtected' file + (\h -> hPutStr h content) + +writeFileProtected' :: FilePath -> (Handle -> IO ()) -> IO () +writeFileProtected' file writer = withUmask 0o0077 $ withFile file WriteMode $ \h -> do void $ tryIO $ modifyFileMode file $ removeModes otherGroupModes - hPutStr h content + writer h |