add unsetFileMode

This commit is contained in:
Joey Hess 2010-11-08 17:44:08 -04:00
parent 6395b790ce
commit 40a815d873

View file

@ -11,17 +11,21 @@ module Utility (
relPathCwdToDir, relPathCwdToDir,
relPathDirToDir, relPathDirToDir,
boolSystem, boolSystem,
shellEscape shellEscape,
unsetFileMode
) where ) where
import System.IO import System.IO
import System.Exit import System.Exit
import System.Posix.Process import System.Posix.Process
import System.Posix.Signals import System.Posix.Signals
import System.Posix.Files
import System.Posix.Types
import Data.String.Utils import Data.String.Utils
import System.Path import System.Path
import System.FilePath import System.FilePath
import System.Directory import System.Directory
import Foreign (complement)
{- A version of hgetContents that is not lazy. Ensures file is {- A version of hgetContents that is not lazy. Ensures file is
- all read before it gets closed. -} - all read before it gets closed. -}
@ -115,3 +119,10 @@ shellEscape f = "'" ++ escaped ++ "'"
where where
-- replace ' with '"'"' -- replace ' with '"'"'
escaped = join "'\"'\"'" $ split "'" f 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)