summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-08 17:44:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-08 17:44:08 -0400
commit40a815d873a828fbccee453f45fc519feffe15fd (patch)
tree413d841d38a96775edda2c163fd7fc65a1c726ad
parent6395b790ce3d2f97803f0c642af71d1a9eb169c6 (diff)
add unsetFileMode
-rw-r--r--Utility.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/Utility.hs b/Utility.hs
index 4e56289e2..0053c687b 100644
--- a/Utility.hs
+++ b/Utility.hs
@@ -11,17 +11,21 @@ module Utility (
relPathCwdToDir,
relPathDirToDir,
boolSystem,
- shellEscape
+ shellEscape,
+ unsetFileMode
) where
import System.IO
import System.Exit
import System.Posix.Process
import System.Posix.Signals
+import System.Posix.Files
+import System.Posix.Types
import Data.String.Utils
import System.Path
import System.FilePath
import System.Directory
+import Foreign (complement)
{- A version of hgetContents that is not lazy. Ensures file is
- all read before it gets closed. -}
@@ -115,3 +119,10 @@ shellEscape f = "'" ++ escaped ++ "'"
where
-- replace ' with '"'"'
escaped = join "'\"'\"'" $ split "'" f
+
+{- Removes a FileMode from a file.
+ - For example, call with otherWriteMode to chmod o-w -}
+unsetFileMode :: FilePath -> FileMode -> IO ()
+unsetFileMode f m = do
+ s <- getFileStatus f
+ setFileMode f $ (fileMode s) `intersectFileModes` (complement m)