aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFreiric Barral <freiric@gmail.com>2014-10-08 23:25:01 +0200
committerFreiric Barral <freiric@gmail.com>2014-10-08 23:25:01 +0200
commit24231623f3e2e44d3035ced7e971f3491f705e46 (patch)
treeccce9824a6514f914e1446e2e39ff243a23b02fb /src
parentd60707eed046979a68b51f03a02ae6163c63a4ac (diff)
downloadpandoc-24231623f3e2e44d3035ced7e971f3491f705e46.tar.gz
fix inDirectory to reset to the original directory in case an exception occurs
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Shared.hs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 6e1f84335..9aa70e6f2 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -735,12 +735,10 @@ renderTags' = renderTagsOptions
-- | Perform an IO action in a directory, returning to starting directory.
inDirectory :: FilePath -> IO a -> IO a
-inDirectory path action = do
- oldDir <- getCurrentDirectory
- setCurrentDirectory path
- result <- action
- setCurrentDirectory oldDir
- return result
+inDirectory path action = E.bracket
+ getCurrentDirectory
+ setCurrentDirectory
+ (const $ setCurrentDirectory path >> action)
readDefaultDataFile :: FilePath -> IO BS.ByteString
readDefaultDataFile fname =