aboutsummaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Exception.hs15
-rw-r--r--Utility/Path.hs1
-rw-r--r--Utility/Tmp.hs5
3 files changed, 11 insertions, 10 deletions
diff --git a/Utility/Exception.hs b/Utility/Exception.hs
index 13000e033..8b110ae6d 100644
--- a/Utility/Exception.hs
+++ b/Utility/Exception.hs
@@ -20,7 +20,8 @@ module Utility.Exception (
catchNonAsync,
tryNonAsync,
tryWhenExists,
- catchHardwareFault,
+ catchIOErrorType,
+ IOErrorType(..)
) where
import Control.Monad.Catch as X hiding (Handler)
@@ -88,11 +89,11 @@ tryWhenExists a = do
v <- tryJust (guard . isDoesNotExistError) a
return (eitherToMaybe v)
-{- Catches only exceptions caused by hardware faults.
- - Ie, disk IO error. -}
-catchHardwareFault :: MonadCatch m => m a -> (IOException -> m a) -> m a
-catchHardwareFault a onhardwareerr = catchIO a onlyhw
+{- Catches only IO exceptions of a particular type.
+ - Ie, use HardwareFault to catch disk IO errors. -}
+catchIOErrorType :: MonadCatch m => IOErrorType -> (IOException -> m a) -> m a -> m a
+catchIOErrorType errtype onmatchingerr a = catchIO a onlymatching
where
- onlyhw e
- | ioeGetErrorType e == HardwareFault = onhardwareerr e
+ onlymatching e
+ | ioeGetErrorType e == errtype = onmatchingerr e
| otherwise = throwM e
diff --git a/Utility/Path.hs b/Utility/Path.hs
index 1771d1e6d..f3290d8d9 100644
--- a/Utility/Path.hs
+++ b/Utility/Path.hs
@@ -288,7 +288,6 @@ fileNameLengthLimit dir = do
if l <= 0
then return 255
else return $ minimum [l, 255]
- where
#endif
{- Given a string that we'd like to use as the basis for FilePath, but that
diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs
index de970fe56..7e4db1101 100644
--- a/Utility/Tmp.hs
+++ b/Utility/Tmp.hs
@@ -88,8 +88,9 @@ withTmpDirIn tmpdir template = bracketIO create remove
makenewdir (tmpdir </> template) (0 :: Int)
makenewdir t n = do
let dir = t ++ "." ++ show n
- either (const $ makenewdir t $ n + 1) (const $ return dir)
- =<< tryIO (createDirectory dir)
+ catchIOErrorType AlreadyExists (const $ makenewdir t $ n + 1) $ do
+ createDirectory dir
+ return dir
{- It's not safe to use a FilePath of an existing file as the template
- for openTempFile, because if the FilePath is really long, the tmpfile