fix toOsPath on windows

After recent changes to use OsPath, test suite fails on windows with:

Exception: Uneven number of bytes: 5. This is not a Word16 bytestream.

Hopefully this fixes it. The innefficiency of the conversion is
unfortunate.
This commit is contained in:
Joey Hess 2025-01-29 14:06:54 -04:00
parent 381019ee3f
commit 9c9baf7c65
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -22,13 +22,16 @@ import Utility.FileSystemEncoding
import System.OsPath
import "os-string" System.OsString.Internal.Types
import qualified Data.ByteString.Short as S
#if defined(mingw32_HOST_OS)
import GHC.IO (unsafePerformIO)
#endif
{- Unlike System.OsString.fromBytes, on Windows this does not ensure a
- valid USC-2LE encoding. The input ByteString must be in a valid encoding
- already or uses of the OsPath will fail. -}
toOsPath :: RawFilePath -> OsPath
#if defined(mingw32_HOST_OS)
toOsPath = OsString . WindowsString . S.toShort
-- On Windows, OsString contains a ShortByteString that is
-- utf-16 encoded. So have to convert the input to that.
-- This is relatively expensive.
toOsPath = unsafePerformIO . encodeFS . fromRawFilePath
#else
toOsPath = OsString . PosixString . S.toShort
#endif