diff options
author | Joey Hess <joey@kitenet.net> | 2012-11-12 17:43:10 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-11-12 17:43:10 -0400 |
commit | c3ec3c211bc90a20391e211bc6defcffe594d139 (patch) | |
tree | 4de01d1f79cd59309231b9da8c0b0ca8df490329 /Utility | |
parent | be133235e4447f98e9e8d870d836b170b0310195 (diff) |
where indentation
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/TempFile.hs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/Utility/TempFile.hs b/Utility/TempFile.hs index 60feb7408..688baa491 100644 --- a/Utility/TempFile.hs +++ b/Utility/TempFile.hs @@ -32,27 +32,27 @@ type Template = String {- Runs an action with a temp file, then removes the file. -} withTempFile :: Template -> (FilePath -> Handle -> IO a) -> IO a withTempFile template a = bracket create remove use - where - create = do - tmpdir <- catchDefaultIO "." getTemporaryDirectory - openTempFile tmpdir template - remove (name, handle) = do - hClose handle - catchBoolIO (removeFile name >> return True) - use (name, handle) = a name handle + where + create = do + tmpdir <- catchDefaultIO "." getTemporaryDirectory + openTempFile tmpdir template + remove (name, handle) = do + hClose handle + catchBoolIO (removeFile name >> return True) + use (name, handle) = a name handle {- Runs an action with a temp directory, then removes the directory and - all its contents. -} withTempDir :: Template -> (FilePath -> IO a) -> IO a withTempDir template = bracket create remove - where - remove = removeDirectoryRecursive - create = do - tmpdir <- catchDefaultIO "." getTemporaryDirectory - createDirectoryIfMissing True tmpdir - pid <- getProcessID - makedir tmpdir (template ++ show pid) (0 :: Int) - makedir tmpdir t n = do - let dir = tmpdir </> t ++ "." ++ show n - r <- tryIO $ createDirectory dir - either (const $ makedir tmpdir t $ n + 1) (const $ return dir) r + where + remove = removeDirectoryRecursive + create = do + tmpdir <- catchDefaultIO "." getTemporaryDirectory + createDirectoryIfMissing True tmpdir + pid <- getProcessID + makedir tmpdir (template ++ show pid) (0 :: Int) + makedir tmpdir t n = do + let dir = tmpdir </> t ++ "." ++ show n + r <- tryIO $ createDirectory dir + either (const $ makedir tmpdir t $ n + 1) (const $ return dir) r |