diff options
author | Joey Hess <joey@kitenet.net> | 2012-09-17 00:18:07 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-09-17 00:18:07 -0400 |
commit | e8188ea611e4c9223492203c0ec0370c3c45b225 (patch) | |
tree | 2a078993be28d1dedc38f8ab9ad193eea0ecf90e /Utility | |
parent | ba744c84a4f683e50bf4c9b8c388e3a611f7fb91 (diff) |
flip catchDefaultIO
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/Directory.hs | 2 | ||||
-rw-r--r-- | Utility/Exception.hs | 8 | ||||
-rw-r--r-- | Utility/FreeDesktop.hs | 3 | ||||
-rw-r--r-- | Utility/TempFile.hs | 4 |
4 files changed, 9 insertions, 8 deletions
diff --git a/Utility/Directory.hs b/Utility/Directory.hs index 057da6087..e6609caf9 100644 --- a/Utility/Directory.hs +++ b/Utility/Directory.hs @@ -43,7 +43,7 @@ dirContentsRecursive topdir = dirContentsRecursive' topdir [""] dirContentsRecursive' :: FilePath -> [FilePath] -> IO [FilePath] dirContentsRecursive' _ [] = return [] dirContentsRecursive' topdir (dir:dirs) = unsafeInterleaveIO $ do - (files, dirs') <- collect [] [] =<< catchDefaultIO (dirContents (topdir </> dir)) [] + (files, dirs') <- collect [] [] =<< catchDefaultIO [] (dirContents (topdir </> dir)) files' <- dirContentsRecursive' topdir (dirs' ++ dirs) return (files ++ files') where diff --git a/Utility/Exception.hs b/Utility/Exception.hs index a6726945c..8b6077743 100644 --- a/Utility/Exception.hs +++ b/Utility/Exception.hs @@ -13,15 +13,15 @@ import Control.Applicative {- Catches IO errors and returns a Bool -} catchBoolIO :: IO Bool -> IO Bool -catchBoolIO a = catchDefaultIO a False +catchBoolIO a = catchDefaultIO False a {- Catches IO errors and returns a Maybe -} catchMaybeIO :: IO a -> IO (Maybe a) -catchMaybeIO a = catchDefaultIO (Just <$> a) Nothing +catchMaybeIO a = catchDefaultIO Nothing $ Just <$> a {- Catches IO errors and returns a default value. -} -catchDefaultIO :: IO a -> a -> IO a -catchDefaultIO a def = catchIO a (const $ return def) +catchDefaultIO :: a -> IO a -> IO a +catchDefaultIO def a = catchIO a (const $ return def) {- Catches IO errors and returns the error message. -} catchMsgIO :: IO a -> IO (Either String a) diff --git a/Utility/FreeDesktop.hs b/Utility/FreeDesktop.hs index a1109f729..0845f3329 100644 --- a/Utility/FreeDesktop.hs +++ b/Utility/FreeDesktop.hs @@ -123,4 +123,5 @@ userDesktopDir = maybe fallback return =<< (parse <$> xdg_user_dir) xdgEnvHome :: String -> String -> IO String xdgEnvHome envbase homedef = do home <- myHomeDir - catchDefaultIO (getEnv $ "XDG_" ++ envbase) (home </> homedef) + catchDefaultIO (home </> homedef) $ + getEnv $ "XDG_" ++ envbase diff --git a/Utility/TempFile.hs b/Utility/TempFile.hs index 2673d47b0..60feb7408 100644 --- a/Utility/TempFile.hs +++ b/Utility/TempFile.hs @@ -34,7 +34,7 @@ withTempFile :: Template -> (FilePath -> Handle -> IO a) -> IO a withTempFile template a = bracket create remove use where create = do - tmpdir <- catchDefaultIO getTemporaryDirectory "." + tmpdir <- catchDefaultIO "." getTemporaryDirectory openTempFile tmpdir template remove (name, handle) = do hClose handle @@ -48,7 +48,7 @@ withTempDir template = bracket create remove where remove = removeDirectoryRecursive create = do - tmpdir <- catchDefaultIO getTemporaryDirectory "." + tmpdir <- catchDefaultIO "." getTemporaryDirectory createDirectoryIfMissing True tmpdir pid <- getProcessID makedir tmpdir (template ++ show pid) (0 :: Int) |