where indentation
This commit is contained in:
parent
5fdbb22973
commit
8a89575526
1 changed files with 19 additions and 19 deletions
|
@ -32,27 +32,27 @@ type Template = String
|
||||||
{- Runs an action with a temp file, then removes the file. -}
|
{- Runs an action with a temp file, then removes the file. -}
|
||||||
withTempFile :: Template -> (FilePath -> Handle -> IO a) -> IO a
|
withTempFile :: Template -> (FilePath -> Handle -> IO a) -> IO a
|
||||||
withTempFile template a = bracket create remove use
|
withTempFile template a = bracket create remove use
|
||||||
where
|
where
|
||||||
create = do
|
create = do
|
||||||
tmpdir <- catchDefaultIO "." getTemporaryDirectory
|
tmpdir <- catchDefaultIO "." getTemporaryDirectory
|
||||||
openTempFile tmpdir template
|
openTempFile tmpdir template
|
||||||
remove (name, handle) = do
|
remove (name, handle) = do
|
||||||
hClose handle
|
hClose handle
|
||||||
catchBoolIO (removeFile name >> return True)
|
catchBoolIO (removeFile name >> return True)
|
||||||
use (name, handle) = a name handle
|
use (name, handle) = a name handle
|
||||||
|
|
||||||
{- Runs an action with a temp directory, then removes the directory and
|
{- Runs an action with a temp directory, then removes the directory and
|
||||||
- all its contents. -}
|
- all its contents. -}
|
||||||
withTempDir :: Template -> (FilePath -> IO a) -> IO a
|
withTempDir :: Template -> (FilePath -> IO a) -> IO a
|
||||||
withTempDir template = bracket create remove
|
withTempDir template = bracket create remove
|
||||||
where
|
where
|
||||||
remove = removeDirectoryRecursive
|
remove = removeDirectoryRecursive
|
||||||
create = do
|
create = do
|
||||||
tmpdir <- catchDefaultIO "." getTemporaryDirectory
|
tmpdir <- catchDefaultIO "." getTemporaryDirectory
|
||||||
createDirectoryIfMissing True tmpdir
|
createDirectoryIfMissing True tmpdir
|
||||||
pid <- getProcessID
|
pid <- getProcessID
|
||||||
makedir tmpdir (template ++ show pid) (0 :: Int)
|
makedir tmpdir (template ++ show pid) (0 :: Int)
|
||||||
makedir tmpdir t n = do
|
makedir tmpdir t n = do
|
||||||
let dir = tmpdir </> t ++ "." ++ show n
|
let dir = tmpdir </> t ++ "." ++ show n
|
||||||
r <- tryIO $ createDirectory dir
|
r <- tryIO $ createDirectory dir
|
||||||
either (const $ makedir tmpdir t $ n + 1) (const $ return dir) r
|
either (const $ makedir tmpdir t $ n + 1) (const $ return dir) r
|
||||||
|
|
Loading…
Add table
Reference in a new issue