RawFilePath conversion of System.Directory
By using System.Directory.OsPath, which takes and returns OsString, which is a ShortByteString. So, things like dirContents currently have the overhead of copying that to a ByteString, but that should be less than the overhead of using Strings which often in turn were converted to RawFilePaths. Added Utility.OsString and the OsString build flag. That flag is turned on in the stack.yaml, and will be turned on automatically by cabal when built with new enough libraries. The stack.yaml change is a bit ugly, and that could be reverted for now if it causes any problems. Note that Utility.OsString.toOsString on windows is avoiding only a check of encoding that is documented as being unlikely to fail. I don't think it can fail in git-annex; if it could, git-annex didn't contain such an encoding check before, so at worst that should be a wash.
This commit is contained in:
parent
e5be81f8d4
commit
1ceece3108
34 changed files with 222 additions and 138 deletions
38
Utility/OsString.hs
Normal file
38
Utility/OsString.hs
Normal file
|
@ -0,0 +1,38 @@
|
|||
{- OsString utilities
|
||||
-
|
||||
- Copyright 2025 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- License: BSD-2-clause
|
||||
-}
|
||||
|
||||
{-# LANGUAGE CPP #-}
|
||||
{-# LANGUAGE PackageImports #-}
|
||||
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
||||
|
||||
module Utility.OsString where
|
||||
|
||||
#ifdef WITH_OSSTRING
|
||||
|
||||
import Utility.RawFilePath
|
||||
|
||||
import "os-string" System.OsString.Internal.Types
|
||||
import qualified Data.ByteString.Short as S
|
||||
|
||||
{- 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 OsString will fail. -}
|
||||
toOsString :: RawFilePath -> OsString
|
||||
#if defined(mingw32_HOST_OS)
|
||||
toOsString = OsString . WindowsString . S.toShort
|
||||
#else
|
||||
toOsString = OsString . PosixString . S.toShort
|
||||
#endif
|
||||
|
||||
fromOsString :: OsString -> RawFilePath
|
||||
#if defined(mingw32_HOST_OS)
|
||||
fromOsString = S.fromShort . getWindowsString . getOsString
|
||||
#else
|
||||
fromOsString = S.fromShort . getPosixString . getOsString
|
||||
#endif
|
||||
|
||||
#endif /* WITH_OSSTRING */
|
Loading…
Add table
Add a link
Reference in a new issue