OsPath build flag no longer depends on filepath-bytestring
However, filepath-bytestring is still in Setup-Depends. That's because Utility.OsPath uses it when not built with OsPath. It would be maybe possible to make Utility.OsPath fall back to using filepath, and eliminate that dependency too, but it would mean either wrapping all of System.FilePath's functions, or using `type OsPath = FilePath` Annex.Import uses ifdefs to avoid converting back to FilePath when not on windows. On windows it's a bit slower due to that conversion. Utility.Path.Windows.convertToWindowsNativeNamespace got a bit slower too, but not really worth optimising I think. Note that importing Utility.FileSystemEncoding at the same time as System.Posix.ByteString will result in conflicting definitions for RawFilePath. filepath-bytestring avoids that by importing RawFilePath from System.Posix.ByteString, but that's not possible in Utility.FileSystemEncoding, since Setup-Depends does not include unix. This turned out not to affect any code in git-annex though. Sponsored-by: Leon Schuermann
This commit is contained in:
parent
ce697aa8ae
commit
2ff716be30
13 changed files with 81 additions and 68 deletions
|
@ -23,7 +23,6 @@ module Utility.FileSystemEncoding (
|
|||
|
||||
import qualified GHC.IO.Encoding as Encoding
|
||||
import System.IO
|
||||
import System.FilePath.ByteString (RawFilePath, encodeFilePath, decodeFilePath)
|
||||
import qualified Data.ByteString as S
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
#ifdef mingw32_HOST_OS
|
||||
|
@ -37,6 +36,9 @@ import Data.Char
|
|||
import Data.List
|
||||
#endif
|
||||
|
||||
-- | A literal file path
|
||||
type RawFilePath = S.ByteString
|
||||
|
||||
{- Makes all subsequent Handles that are opened, as well as stdio Handles,
|
||||
- use the filesystem encoding, instead of the encoding of the current
|
||||
- locale.
|
||||
|
@ -90,9 +92,7 @@ encodeBL = L8.fromString
|
|||
decodeBS :: S.ByteString -> FilePath
|
||||
#ifndef mingw32_HOST_OS
|
||||
-- This does the same thing as System.FilePath.ByteString.decodeFilePath,
|
||||
-- with an identical implementation. However, older versions of that library
|
||||
-- truncated at NUL, which this must not do, because it may end up used on
|
||||
-- something other than a unix filepath.
|
||||
-- with an identical implementation.
|
||||
{-# NOINLINE decodeBS #-}
|
||||
decodeBS b = unsafePerformIO $ do
|
||||
enc <- Encoding.getFileSystemEncoding
|
||||
|
@ -104,9 +104,7 @@ decodeBS = S8.toString
|
|||
encodeBS :: FilePath -> S.ByteString
|
||||
#ifndef mingw32_HOST_OS
|
||||
-- This does the same thing as System.FilePath.ByteString.encodeFilePath,
|
||||
-- with an identical implementation. However, older versions of that library
|
||||
-- truncated at NUL, which this must not do, because it may end up used on
|
||||
-- something other than a unix filepath.
|
||||
-- with an identical implementation.
|
||||
{-# NOINLINE encodeBS #-}
|
||||
encodeBS f = unsafePerformIO $ do
|
||||
enc <- Encoding.getFileSystemEncoding
|
||||
|
@ -116,10 +114,10 @@ encodeBS = S8.fromString
|
|||
#endif
|
||||
|
||||
fromRawFilePath :: RawFilePath -> FilePath
|
||||
fromRawFilePath = decodeFilePath
|
||||
fromRawFilePath = decodeBS
|
||||
|
||||
toRawFilePath :: FilePath -> RawFilePath
|
||||
toRawFilePath = encodeFilePath
|
||||
toRawFilePath = encodeBS
|
||||
|
||||
{- Truncates a FilePath to the given number of bytes (or less),
|
||||
- as represented on disk.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue