{-# LANGUAGE CPP #-}
module Darcs.Util.Workaround
( setExecutable
, getCurrentDirectory
, installHandler
, raiseSignal
, Handler(..)
, Signal
, sigINT
, sigHUP
, sigABRT
, sigALRM
, sigTERM
, sigPIPE
) where
import Darcs.Prelude
#ifdef WIN32
import qualified System.Directory ( getCurrentDirectory )
#else
import System.Posix.Signals(installHandler, raiseSignal, Handler(..), Signal,
sigINT, sigHUP, sigABRT, sigALRM, sigTERM, sigPIPE)
import System.Directory ( getCurrentDirectory )
import System.Posix.Files (fileMode,getFileStatus, setFileMode,
setFileCreationMask,
ownerReadMode, ownerWriteMode, ownerExecuteMode,
groupReadMode, groupWriteMode, groupExecuteMode,
otherReadMode, otherWriteMode, otherExecuteMode)
import Data.Bits ( (.&.), (.|.), complement )
#endif
#ifdef WIN32
data Handler = Default
| Ignore
| Catch (IO ())
type Signal = Int
installHandler :: Signal
-> Handler
-> Maybe ()
-> IO ()
installHandler _ _ _ = return ()
raiseSignal :: Signal -> IO ()
raiseSignal _ = return ()
sigINT :: Signal
sigINT = 0
sigHUP :: Signal
sigHUP = 0
sigABRT :: Signal
sigABRT = 0
sigTERM :: Signal
sigTERM = 0
sigPIPE :: Signal
sigPIPE = 0
sigALRM :: Signal
sigALRM = 0
setExecutable :: FilePath
-> Bool
-> IO ()
setExecutable _ _ = return ()
getCurrentDirectory :: IO FilePath
getCurrentDirectory = do
d <- System.Directory.getCurrentDirectory
return $ map rb d
where
rb '\\' = '/'
rb c = c
#else
setExecutable :: FilePath
-> Bool
-> IO ()
setExecutable :: FilePath -> Bool -> IO ()
setExecutable FilePath
f Bool
ex = do
FileStatus
st <- FilePath -> IO FileStatus
getFileStatus FilePath
f
FileMode
umask <- FileMode -> IO FileMode
setFileCreationMask FileMode
0
FileMode
_ <- FileMode -> IO FileMode
setFileCreationMask FileMode
umask
let rw :: FileMode
rw = FileStatus -> FileMode
fileMode FileStatus
st FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.&.
(FileMode
ownerReadMode FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.|. FileMode
ownerWriteMode FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.|.
FileMode
groupReadMode FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.|. FileMode
groupWriteMode FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.|.
FileMode
otherReadMode FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.|. FileMode
otherWriteMode)
total :: FileMode
total = if Bool
ex then FileMode
rw FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.|.
((FileMode
ownerExecuteMode FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.|. FileMode
groupExecuteMode FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.|. FileMode
otherExecuteMode)
FileMode -> FileMode -> FileMode
forall a. Bits a => a -> a -> a
.&. FileMode -> FileMode
forall a. Bits a => a -> a
complement FileMode
umask)
else FileMode
rw
FilePath -> FileMode -> IO ()
setFileMode FilePath
f FileMode
total
#endif