summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-10-08 15:48:59 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-10-08 15:48:59 -0700
commit8b60d430f2095c42daf26f2921359d5c49f0757d (patch)
treecc6971239704120fd1c261c7d9eab1a1d2e05468 /src
parent2eaa0f6ab168bf9ebb97ee39949d4935cc5faef0 (diff)
parent24231623f3e2e44d3035ced7e971f3491f705e46 (diff)
Merge pull request #1674 from freiric/master
fix inDirectory to reset to the original directory in case an exception ...
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 =