{-# OPTIONS_GHC -cpp #-}{-# LANGUAGE CPP #-}moduleWorkaround(renameFile,setExecutable,getCurrentDirectory,installHandler,raiseSignal,Handler(..),Signal,sigINT,sigHUP,sigABRT,sigALRM,sigTERM,sigPIPE)where#ifdef WIN32importqualifiedSystem.Directory(renameFile,getCurrentDirectory,removeFile)importqualifiedControl.Exception(block)importqualifiedSystem.IO.Error(isDoesNotExistError,ioError,catch)#elseimportSystem.Posix.Signals(installHandler,raiseSignal,Handler(..),Signal,sigINT,sigHUP,sigABRT,sigALRM,sigTERM,sigPIPE)importSystem.Directory(renameFile,getCurrentDirectory)importSystem.Posix.Files(fileMode,getFileStatus,setFileMode,setFileCreationMask,ownerReadMode,ownerWriteMode,ownerExecuteMode,groupReadMode,groupWriteMode,groupExecuteMode,otherReadMode,otherWriteMode,otherExecuteMode)importData.Bits((.&.),(.|.),complement)#endif#ifdef WIN32-- Dummy implementation of POSIX signalsdataHandler=Default|Ignore|Catch(IO())typeSignal=IntinstallHandler::Signal->Handler->Maybe()->IO()installHandler___=return()raiseSignal::Signal->IO()raiseSignal_=return()sigINT,{- sigKILL, -}sigHUP,{- sigQUIT, -}sigABRT,sigALRM,sigTERM,sigPIPE::SignalsigINT=0-- not used: sigKILL = 0sigHUP=0-- not used: sigQUIT = 0sigABRT=0sigTERM=0sigPIPE=0sigALRM=0{-
System.Directory.renameFile incorrectly fails when the new file already
exists. This code works around that bug at the cost of losing atomic
writes.
-}renameFile::FilePath->FilePath->IO()renameFileoldnew=Control.Exception.block$System.Directory.renameFileoldnew`System.IO.Error.catch`\_->doSystem.Directory.removeFilenew`System.IO.Error.catch`(\e->ifSystem.IO.Error.isDoesNotExistErrorethenreturn()elseSystem.IO.Error.ioErrore)System.Directory.renameFileoldnewsetExecutable::FilePath->Bool->IO()setExecutable__=return(){-
System.Directory.getCurrentDirectory returns a path with backslashes in it
under windows, and some of the code gets confused by that, so we override
getCurrentDirectory and translates '\\' to '/'
-}getCurrentDirectory::IOFilePathgetCurrentDirectory=dod<-System.Directory.getCurrentDirectoryreturn$maprbdwhererb'\\'='/'rbc=c#elsesetExecutable::FilePath->Bool->IO()setExecutablefex=dost<-getFileStatusfumask<-setFileCreationMask0setFileCreationMaskumaskletrw=fileModest.&.(ownerReadMode.|.ownerWriteMode.|.groupReadMode.|.groupWriteMode.|.otherReadMode.|.otherWriteMode)total=ifexthenrw.|.((ownerExecuteMode.|.groupExecuteMode.|.otherExecuteMode).&.complementumask)elserwsetFileModeftotal#endif