diff options
author | Joey Hess <joey@kitenet.net> | 2013-05-21 13:03:46 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-05-21 13:03:46 -0400 |
commit | 75002b45b04961beca948dda19b9ab6439953001 (patch) | |
tree | 60a51d478464babced2b4471b18dbe846e8ac604 /Utility/Exception.hs | |
parent | 75638200a08e25333530946597e30b8ae74743c4 (diff) |
better nukefile
Fixed handling of case when file does not exist to work like it did before,
and avoid an excess stat call.
Diffstat (limited to 'Utility/Exception.hs')
-rw-r--r-- | Utility/Exception.hs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Utility/Exception.hs b/Utility/Exception.hs index 45f2aecec..bc928e18e 100644 --- a/Utility/Exception.hs +++ b/Utility/Exception.hs @@ -12,6 +12,8 @@ module Utility.Exception where import Prelude hiding (catch) import Control.Exception import Control.Applicative +import Control.Monad +import System.IO.Error (isDoesNotExistError) {- Catches IO errors and returns a Bool -} catchBoolIO :: IO Bool -> IO Bool @@ -49,3 +51,8 @@ catchNonAsync a onerr = a `catches` tryNonAsync :: IO a -> IO (Either SomeException a) tryNonAsync a = (Right <$> a) `catchNonAsync` (return . Left) + +{- Catches only DoesNotExist exceptions, and lets all others through. -} +tryWhenExists :: IO a -> IO (Maybe a) +tryWhenExists a = either (const Nothing) Just <$> + tryJust (guard . isDoesNotExistError) a |