Permalink
Browse files

Fixed withTempDir so it returns to old directory.

Closes #303.  This is a slightly different solution than the one
proposed by tstgruby, but it has the advantage that only withTempDir
itself needs to be changed.
  • Loading branch information...
jgm committed Jun 25, 2012
1 parent 0badae9 commit 2cd8ca6cf325071c4ed52d8a785307b6b453b647
Showing with 5 additions and 1 deletion.
  1. +5 −1 Network/Gitit/Util.hs
View
@@ -61,7 +61,11 @@ inDir d action = do
-- | Perform a function in a temporary directory and clean up.
withTempDir :: FilePath -> (FilePath -> IO a) -> IO a
-withTempDir baseName = bracket (createTempDir 0 baseName) removeDirectoryRecursive
+withTempDir baseName f = do
+ oldDir <- getCurrentDirectory
+ bracket (createTempDir 0 baseName)
+ (\tmp -> setCurrentDirectory oldDir >> removeDirectoryRecursive tmp)
+ f
-- | Create a temporary directory with a unique name.
createTempDir :: Integer -> FilePath -> IO FilePath

1 comment on commit 2cd8ca6

@tstgruby

This comment has been minimized.

Show comment Hide comment
@tstgruby

tstgruby Jun 26, 2012

Nice, I didn't think of that possiblity.

Nice, I didn't think of that possiblity.

Please sign in to comment.