fix FileIO openTempFile on Windows

When an UNC-style path is passed into openTempFile, the returned file
starts with that same style of path. Which can cause problems, eg piping
that filename to git failed. So, convert the output filename to be
relative to the input temp directory.
This commit is contained in:
Joey Hess 2025-01-30 14:23:00 -04:00
parent 97c83152d6
commit bd5d2b0782
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -37,7 +37,9 @@ import System.File.OsPath
-- https://github.com/haskell/file-io/issues/39
import Utility.Path.Windows
import Utility.OsPath
import System.OsPath
import System.IO (IO, Handle, IOMode)
import Prelude (return)
import qualified System.File.OsPath as O
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
@ -96,7 +98,10 @@ appendFile' f b = do
openTempFile :: OsPath -> OsPath -> IO (OsPath, Handle)
openTempFile p s = do
p' <- toOsPath <$> convertToWindowsNativeNamespace (fromOsPath p)
O.openTempFile p' s
(t, h) <- O.openTempFile p' s
-- Avoid returning mangled path from convertToWindowsNativeNamespace
let t' = p </> takeFileName t
return (t', h)
#endif
#else