From 67635f72b8a36be575b6046b84d2e95ffb46b923 Mon Sep 17 00:00:00 2001 From: James Cook Date: Tue, 18 Aug 2009 23:12:15 +0000 Subject: [PATCH] Fix mkTemp, et al. to handle the case where an X appears in the dir part of the template. This happens quite often on Mac OS X in my experience. $TMPDIR is set to a private location with the name apparently generated by some hashing algorithm. I wouldn't be surprised if it is derived from the username somehow, as my accounts consistently wind up with 'X's in their $TMPDIR, on many systems. --- src/System/MkTemp.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/System/MkTemp.hs b/src/System/MkTemp.hs index f071ce6..bda7ba1 100644 --- a/src/System/MkTemp.hs +++ b/src/System/MkTemp.hs @@ -40,6 +40,7 @@ import Data.List import Data.Char ( chr, ord, isDigit ) import Control.Monad ( liftM ) import Control.Exception ( handleJust ) +import System.FilePath ( splitFileName, () ) import System.Directory ( doesDirectoryExist, doesFileExist, createDirectory ) import System.IO #ifndef __MINGW32__ @@ -90,8 +91,9 @@ gettemp path doopen domkdir slen = do -- firstly, break up the path and extract the template -- let (pref,tmpl,suff) = let (r,s) = splitAt (length path - slen) path - (p,t) = break (== 'X') r - in (p,t,s) + (d,f) = splitFileName r + (p,t) = break (== 'X') f + in (d p,t,s) -- -- an error if there is only a suffix, it seems --