avoid looping trying to make temp dir when the name is too long
authorJoey Hess <joeyh@joeyh.name>
Sun, 6 Dec 2015 20:29:36 +0000 (16:29 -0400)
committerJoey Hess <joeyh@joeyh.name>
Sun, 6 Dec 2015 20:29:36 +0000 (16:29 -0400)
Only loop when directory creation fails due to the directory existing
already.

Utility/Tmp.hs

index de970fe56e36e39045f8b2550454f514e00a4056..7e4db1101bea01765e918125364fa8b2a97b6719 100644 (file)
@@ -88,8 +88,9 @@ withTmpDirIn tmpdir template = bracketIO create remove
                makenewdir (tmpdir </> template) (0 :: Int)
        makenewdir t n = do
                let dir = t ++ "." ++ show n
-               either (const $ makenewdir t $ n + 1) (const $ return dir)
-                       =<< tryIO (createDirectory dir)
+               catchIOErrorType AlreadyExists (const $ makenewdir t $ n + 1) $ do
+                       createDirectory dir
+                       return dir
 
 {- It's not safe to use a FilePath of an existing file as the template
  - for openTempFile, because if the FilePath is really long, the tmpfile