summaryrefslogtreecommitdiff
path: root/Utility/Tmp.hs
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2014-10-12 14:32:56 -0400
committerJoey Hess <joey@kitenet.net>2014-10-12 14:32:56 -0400
commitefef527d5b2e42e261fa7af6947aad6553426ebe (patch)
tree082a5dad993557e9dffd76a69d4087371da8ed42 /Utility/Tmp.hs
parentab1cf3570207bd08ae0abbba183a8c570c0361f5 (diff)
downloadgit-repair-efef527d5b2e42e261fa7af6947aad6553426ebe.tar.gz
Merge from git-annex.
Includes changing to new exceptions library, and some whitespace fixes.
Diffstat (limited to 'Utility/Tmp.hs')
-rw-r--r--Utility/Tmp.hs24
1 files changed, 12 insertions, 12 deletions
diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs
index bed30bb..edd82f5 100644
--- a/Utility/Tmp.hs
+++ b/Utility/Tmp.hs
@@ -9,11 +9,11 @@
module Utility.Tmp where
-import Control.Exception (bracket)
import System.IO
import System.Directory
import Control.Monad.IfElse
import System.FilePath
+import Control.Monad.IO.Class
import Utility.Exception
import Utility.FileSystemEncoding
@@ -32,31 +32,31 @@ viaTmp a file content = bracket setup cleanup use
setup = do
createDirectoryIfMissing True dir
openTempFile dir template
- cleanup (tmpfile, handle) = do
- _ <- tryIO $ hClose handle
+ cleanup (tmpfile, h) = do
+ _ <- tryIO $ hClose h
tryIO $ removeFile tmpfile
- use (tmpfile, handle) = do
- hClose handle
+ use (tmpfile, h) = do
+ hClose h
a tmpfile content
rename tmpfile file
{- Runs an action with a tmp file located in the system's tmp directory
- (or in "." if there is none) then removes the file. -}
-withTmpFile :: Template -> (FilePath -> Handle -> IO a) -> IO a
+withTmpFile :: (MonadIO m, MonadMask m) => Template -> (FilePath -> Handle -> m a) -> m a
withTmpFile template a = do
- tmpdir <- catchDefaultIO "." getTemporaryDirectory
+ tmpdir <- liftIO $ catchDefaultIO "." getTemporaryDirectory
withTmpFileIn tmpdir template a
{- Runs an action with a tmp file located in the specified directory,
- then removes the file. -}
-withTmpFileIn :: FilePath -> Template -> (FilePath -> Handle -> IO a) -> IO a
+withTmpFileIn :: (MonadIO m, MonadMask m) => FilePath -> Template -> (FilePath -> Handle -> m a) -> m a
withTmpFileIn tmpdir template a = bracket create remove use
where
- create = openTempFile tmpdir template
- remove (name, handle) = do
- hClose handle
+ create = liftIO $ openTempFile tmpdir template
+ remove (name, h) = liftIO $ do
+ hClose h
catchBoolIO (removeFile name >> return True)
- use (name, handle) = a name handle
+ use (name, h) = a name h
{- Runs an action with a tmp directory located within the system's tmp
- directory (or within "." if there is none), then removes the tmp