rename OsString to OsPath

This commit is contained in:
Joey Hess 2025-01-21 11:57:44 -04:00
parent 88b88c9d26
commit 71f83bfff7
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 25 additions and 24 deletions

View file

@ -25,8 +25,8 @@ import Utility.Monad
import Utility.FileSystemEncoding import Utility.FileSystemEncoding
import qualified Utility.RawFilePath as R import qualified Utility.RawFilePath as R
#ifdef WITH_OSSTRING #ifdef WITH_OSPATH
import Utility.OsString import Utility.OsPath
import qualified System.Directory.OsPath as OP import qualified System.Directory.OsPath as OP
#else #else
import Utility.SystemDirectory import Utility.SystemDirectory
@ -45,9 +45,9 @@ dirCruft' _ = False
{- Lists the contents of a directory. {- Lists the contents of a directory.
- Unlike getDirectoryContents, paths are not relative to the directory. -} - Unlike getDirectoryContents, paths are not relative to the directory. -}
dirContents :: RawFilePath -> IO [RawFilePath] dirContents :: RawFilePath -> IO [RawFilePath]
#ifdef WITH_OSSTRING #ifdef WITH_OSPATH
dirContents d = map (\p -> d P.</> fromOsString p) dirContents d = map (\p -> d P.</> fromOsPath p)
<$> OP.listDirectory (toOsString d) <$> OP.listDirectory (toOsPath d)
#else #else
dirContents d = dirContents d =
map (\p -> d P.</> toRawFilePath p) map (\p -> d P.</> toRawFilePath p)
@ -102,8 +102,8 @@ dirContentsRecursiveSkipping skipdir followsubdirsymlinks topdir
(Just s) (Just s)
| isDirectory s -> recurse | isDirectory s -> recurse
| isSymbolicLink s && followsubdirsymlinks -> | isSymbolicLink s && followsubdirsymlinks ->
#ifdef WITH_OSSTRING #ifdef WITH_OSPATH
ifM (OP.doesDirectoryExist (toOsString entry)) ifM (OP.doesDirectoryExist (toOsPath entry))
#else #else
ifM (doesDirectoryExist (fromRawFilePath entry)) ifM (doesDirectoryExist (fromRawFilePath entry))
#endif #endif

View file

@ -1,4 +1,4 @@
{- OsString utilities {- OsPath utilities
- -
- Copyright 2025 Joey Hess <id@joeyh.name> - Copyright 2025 Joey Hess <id@joeyh.name>
- -
@ -9,30 +9,31 @@
{-# LANGUAGE PackageImports #-} {-# LANGUAGE PackageImports #-}
{-# OPTIONS_GHC -fno-warn-tabs #-} {-# OPTIONS_GHC -fno-warn-tabs #-}
module Utility.OsString where module Utility.OsPath where
#ifdef WITH_OSSTRING #ifdef WITH_OSPATH
import Utility.RawFilePath import Utility.RawFilePath
import System.OsPath
import "os-string" System.OsString.Internal.Types import "os-string" System.OsString.Internal.Types
import qualified Data.ByteString.Short as S import qualified Data.ByteString.Short as S
{- Unlike System.OsString.fromBytes, on Windows this does not ensure a {- Unlike System.OsString.fromBytes, on Windows this does not ensure a
- valid USC-2LE encoding. The input ByteString must be in a valid encoding - valid USC-2LE encoding. The input ByteString must be in a valid encoding
- already or uses of the OsString will fail. -} - already or uses of the OsPath will fail. -}
toOsString :: RawFilePath -> OsString toOsPath :: RawFilePath -> OsPath
#if defined(mingw32_HOST_OS) #if defined(mingw32_HOST_OS)
toOsString = OsString . WindowsString . S.toShort toOsPath = OsString . WindowsString . S.toShort
#else #else
toOsString = OsString . PosixString . S.toShort toOsPath = OsString . PosixString . S.toShort
#endif #endif
fromOsString :: OsString -> RawFilePath fromOsPath :: OsPath -> RawFilePath
#if defined(mingw32_HOST_OS) #if defined(mingw32_HOST_OS)
fromOsString = S.fromShort . getWindowsString . getOsString fromOsPath = S.fromShort . getWindowsString . getOsString
#else #else
fromOsString = S.fromShort . getPosixString . getOsString fromOsPath = S.fromShort . getPosixString . getOsString
#endif #endif
#endif /* WITH_OSSTRING */ #endif /* WITH_OSPATH */

View file

@ -175,8 +175,8 @@ Flag Crypton
Flag Servant Flag Servant
Description: Use the servant library, enabling using annex+http urls and git-annex p2phttp Description: Use the servant library, enabling using annex+http urls and git-annex p2phttp
Flag OsString Flag OsPath
Description: Use the os-string library Description: Use the os-string library and related libraries, for faster filename manipulation
Flag Benchmark Flag Benchmark
Description: Enable benchmarking Description: Enable benchmarking
@ -332,12 +332,12 @@ Executable git-annex
P2P.Http.Server P2P.Http.Server
P2P.Http.State P2P.Http.State
if flag(OsString) if flag(OsPath)
Build-Depends: Build-Depends:
os-string (>= 2.0.0), os-string (>= 2.0.0),
directory (>= 1.3.8.3), directory (>= 1.3.8.3),
filepath (>= 1.5.2.0) filepath (>= 1.5.2.0)
CPP-Options: -DWITH_OSSTRING CPP-Options: -DWITH_OSPATH
if (os(windows)) if (os(windows))
Build-Depends: Build-Depends:
@ -1104,7 +1104,7 @@ Executable git-annex
Utility.OpenFile Utility.OpenFile
Utility.OptParse Utility.OptParse
Utility.OSX Utility.OSX
Utility.OsString Utility.OsPath
Utility.PID Utility.PID
Utility.PartialPrelude Utility.PartialPrelude
Utility.Path Utility.Path

View file

@ -11,7 +11,7 @@ flags:
benchmark: true benchmark: true
crypton: true crypton: true
servant: true servant: true
osstring: true ospath: true
packages: packages:
- '.' - '.'
resolver: nightly-2025-01-20 resolver: nightly-2025-01-20