generalize to MonadIO
This commit is contained in:
parent
aa4192aea6
commit
cd22340c99
1 changed files with 6 additions and 4 deletions
|
@ -20,6 +20,8 @@ import Utility.PosixFiles
|
||||||
import System.Posix.Files
|
import System.Posix.Files
|
||||||
#endif
|
#endif
|
||||||
import Foreign (complement)
|
import Foreign (complement)
|
||||||
|
import Control.Monad.IO.Class (liftIO, MonadIO)
|
||||||
|
import Control.Monad.Catch
|
||||||
|
|
||||||
import Utility.Exception
|
import Utility.Exception
|
||||||
|
|
||||||
|
@ -95,7 +97,7 @@ isExecutable mode = combineModes executeModes `intersectFileModes` mode /= 0
|
||||||
|
|
||||||
{- Runs an action without that pesky umask influencing it, unless the
|
{- Runs an action without that pesky umask influencing it, unless the
|
||||||
- passed FileMode is the standard one. -}
|
- passed FileMode is the standard one. -}
|
||||||
noUmask :: FileMode -> IO a -> IO a
|
noUmask :: (MonadIO m, MonadMask m) => FileMode -> m a -> m a
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
noUmask mode a
|
noUmask mode a
|
||||||
| mode == stdFileMode = a
|
| mode == stdFileMode = a
|
||||||
|
@ -104,12 +106,12 @@ noUmask mode a
|
||||||
noUmask _ a = a
|
noUmask _ a = a
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
withUmask :: FileMode -> IO a -> IO a
|
withUmask :: (MonadIO m, MonadMask m) => FileMode -> m a -> m a
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
withUmask umask a = bracket setup cleanup go
|
withUmask umask a = bracket setup cleanup go
|
||||||
where
|
where
|
||||||
setup = setFileCreationMask umask
|
setup = liftIO $ setFileCreationMask umask
|
||||||
cleanup = setFileCreationMask
|
cleanup = liftIO . setFileCreationMask
|
||||||
go _ = a
|
go _ = a
|
||||||
#else
|
#else
|
||||||
withUmask _ a = a
|
withUmask _ a = a
|
||||||
|
|
Loading…
Reference in a new issue