rename OsString to OsPath
This commit is contained in:
parent
88b88c9d26
commit
71f83bfff7
4 changed files with 25 additions and 24 deletions
|
@ -25,8 +25,8 @@ import Utility.Monad
|
|||
import Utility.FileSystemEncoding
|
||||
import qualified Utility.RawFilePath as R
|
||||
|
||||
#ifdef WITH_OSSTRING
|
||||
import Utility.OsString
|
||||
#ifdef WITH_OSPATH
|
||||
import Utility.OsPath
|
||||
import qualified System.Directory.OsPath as OP
|
||||
#else
|
||||
import Utility.SystemDirectory
|
||||
|
@ -45,9 +45,9 @@ dirCruft' _ = False
|
|||
{- Lists the contents of a directory.
|
||||
- Unlike getDirectoryContents, paths are not relative to the directory. -}
|
||||
dirContents :: RawFilePath -> IO [RawFilePath]
|
||||
#ifdef WITH_OSSTRING
|
||||
dirContents d = map (\p -> d P.</> fromOsString p)
|
||||
<$> OP.listDirectory (toOsString d)
|
||||
#ifdef WITH_OSPATH
|
||||
dirContents d = map (\p -> d P.</> fromOsPath p)
|
||||
<$> OP.listDirectory (toOsPath d)
|
||||
#else
|
||||
dirContents d =
|
||||
map (\p -> d P.</> toRawFilePath p)
|
||||
|
@ -102,8 +102,8 @@ dirContentsRecursiveSkipping skipdir followsubdirsymlinks topdir
|
|||
(Just s)
|
||||
| isDirectory s -> recurse
|
||||
| isSymbolicLink s && followsubdirsymlinks ->
|
||||
#ifdef WITH_OSSTRING
|
||||
ifM (OP.doesDirectoryExist (toOsString entry))
|
||||
#ifdef WITH_OSPATH
|
||||
ifM (OP.doesDirectoryExist (toOsPath entry))
|
||||
#else
|
||||
ifM (doesDirectoryExist (fromRawFilePath entry))
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{- OsString utilities
|
||||
{- OsPath utilities
|
||||
-
|
||||
- Copyright 2025 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
|
@ -9,30 +9,31 @@
|
|||
{-# LANGUAGE PackageImports #-}
|
||||
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
||||
|
||||
module Utility.OsString where
|
||||
module Utility.OsPath where
|
||||
|
||||
#ifdef WITH_OSSTRING
|
||||
#ifdef WITH_OSPATH
|
||||
|
||||
import Utility.RawFilePath
|
||||
|
||||
import System.OsPath
|
||||
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
|
||||
- already or uses of the OsPath will fail. -}
|
||||
toOsPath :: RawFilePath -> OsPath
|
||||
#if defined(mingw32_HOST_OS)
|
||||
toOsString = OsString . WindowsString . S.toShort
|
||||
toOsPath = OsString . WindowsString . S.toShort
|
||||
#else
|
||||
toOsString = OsString . PosixString . S.toShort
|
||||
toOsPath = OsString . PosixString . S.toShort
|
||||
#endif
|
||||
|
||||
fromOsString :: OsString -> RawFilePath
|
||||
fromOsPath :: OsPath -> RawFilePath
|
||||
#if defined(mingw32_HOST_OS)
|
||||
fromOsString = S.fromShort . getWindowsString . getOsString
|
||||
fromOsPath = S.fromShort . getWindowsString . getOsString
|
||||
#else
|
||||
fromOsString = S.fromShort . getPosixString . getOsString
|
||||
fromOsPath = S.fromShort . getPosixString . getOsString
|
||||
#endif
|
||||
|
||||
#endif /* WITH_OSSTRING */
|
||||
#endif /* WITH_OSPATH */
|
Loading…
Add table
Add a link
Reference in a new issue