Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 2cd8ca6cf325071c4ed52d8a785307b6b453b647 1 parent 0badae9
@jgm authored
Showing with 5 additions and 1 deletion.
  1. +5 −1 Network/Gitit/Util.hs
View
6 Network/Gitit/Util.hs
@@ -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

Nice, I didn't think of that possiblity.

Please sign in to comment.
Something went wrong with that request. Please try again.