summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorKonstantin Zudov <konstantin@anche.no>2014-11-07 07:32:48 -0600
committerAustin Seipp <austin@well-typed.com>2014-11-07 07:32:48 -0600
commitf14ac52a9296b378c75ea75c94f51ff1f377111e (patch)
tree9b2112556d06f653a9451eb0a363f043c629ab39 /utils
parentb0d5b5b338ab6ebbc90f94243b83d2a738982f88 (diff)
downloadhaskell-f14ac52a9296b378c75ea75c94f51ff1f377111e.tar.gz
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
Diffstat (limited to 'utils')
-rw-r--r--utils/ghc-cabal/Main.hs9
1 files changed, 3 insertions, 6 deletions
diff --git a/utils/ghc-cabal/Main.hs b/utils/ghc-cabal/Main.hs
index bf08912c74..1847aafce5 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