[commit: ghc] master: Use bracket in `withCurrentDirectory` (f14ac52)
git at git.haskell.org
git at git.haskell.org
Fri Nov 7 13:32:57 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/f14ac52a9296b378c75ea75c94f51ff1f377111e/ghc
>---------------------------------------------------------------
commit f14ac52a9296b378c75ea75c94f51ff1f377111e
Author: Konstantin Zudov <konstantin at anche.no>
Date: Fri Nov 7 07:32:48 2014 -0600
Use bracket in `withCurrentDirectory`
Summary: There was a comment about that. Seems like a better behaviour.
Reviewers: austin
Reviewed By: austin
Subscribers: thomie, carter, simonmar
Differential Revision: https://phabricator.haskell.org/D419
>---------------------------------------------------------------
f14ac52a9296b378c75ea75c94f51ff1f377111e
utils/ghc-cabal/Main.hs | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/utils/ghc-cabal/Main.hs b/utils/ghc-cabal/Main.hs
index bf08912..1847aaf 100644
--- a/utils/ghc-cabal/Main.hs
+++ b/utils/ghc-cabal/Main.hs
@@ -21,6 +21,7 @@ import Distribution.Verbosity
import qualified Distribution.InstalledPackageInfo as Installed
import qualified Distribution.Simple.PackageIndex as PackageIndex
+import Control.Exception (bracket)
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.List
@@ -70,14 +71,10 @@ die :: [String] -> IO a
die errs = do mapM_ (hPutStrLn stderr) errs
exitWith (ExitFailure 1)
--- XXX Should use bracket
withCurrentDirectory :: FilePath -> IO a -> IO a
withCurrentDirectory directory io
- = do curDirectory <- getCurrentDirectory
- setCurrentDirectory directory
- r <- io
- setCurrentDirectory curDirectory
- return r
+ = bracket (getCurrentDirectory) (setCurrentDirectory)
+ (const (setCurrentDirectory directory >> io))
-- We need to use the autoconfUserHooks, as the packages that use
-- configure can create a .buildinfo file, and we need any info that
More information about the ghc-commits
mailing list