@@ -384,13 +384,15 @@ fromTarPathToWindowsPath :: TarPath -> FilePath
384
384
fromTarPathToWindowsPath = BS.Char8. unpack . fromTarPathInternal FilePath.Windows. pathSeparator
385
385
386
386
fromTarPathInternal :: Char -> TarPath -> BS. ByteString
387
- fromTarPathInternal sep (TarPath name prefix)
388
- | BS. null prefix = adjustSeps name
389
- | BS. null name = adjustSeps prefix
390
- | sep == FilePath.Posix. pathSeparator = prefix <> BS.Char8. cons sep name
391
- | otherwise = adjustSeps prefix <> BS.Char8. cons sep (adjustSeps name)
387
+ fromTarPathInternal sep = go
392
388
where
393
- adjustSeps = BS.Char8. map $ \ c -> if c == FilePath.Posix. pathSeparator then sep else c
389
+ posixSep = FilePath.Posix. pathSeparator
390
+ adjustSeps = if sep == posixSep then id else
391
+ BS.Char8. map $ \ c -> if c == posixSep then sep else c
392
+ go (TarPath name prefix)
393
+ | BS. null prefix = adjustSeps name
394
+ | BS. null name = adjustSeps prefix
395
+ | otherwise = adjustSeps prefix <> BS.Char8. cons sep (adjustSeps name)
394
396
{-# INLINE fromTarPathInternal #-}
395
397
396
398
-- | Convert a native 'FilePath' to a 'TarPath'.
@@ -528,21 +530,20 @@ fromLinkTargetToWindowsPath (LinkTarget pathbs) =
528
530
529
531
-- | Convert a unix FilePath to a native 'FilePath'.
530
532
fromFilePathToNative :: FilePath -> FilePath
531
- fromFilePathToNative path = adjustDirectory $
532
- FilePath.Native. joinPath $ FilePath.Posix. splitDirectories path
533
- where
534
- adjustDirectory | FilePath.Posix. hasTrailingPathSeparator path
535
- = FilePath.Native. addTrailingPathSeparator
536
- | otherwise = id
533
+ fromFilePathToNative =
534
+ fromFilePathInternal FilePath.Posix. pathSeparator FilePath.Native. pathSeparator
537
535
538
536
-- | Convert a unix FilePath to a Windows 'FilePath'.
539
537
fromFilePathToWindowsPath :: FilePath -> FilePath
540
- fromFilePathToWindowsPath path = adjustDirectory $
541
- FilePath.Windows. joinPath $ FilePath.Posix. splitDirectories path
538
+ fromFilePathToWindowsPath =
539
+ fromFilePathInternal FilePath.Posix. pathSeparator FilePath.Windows. pathSeparator
540
+
541
+ fromFilePathInternal :: Char -> Char -> FilePath -> FilePath
542
+ fromFilePathInternal fromSep toSep = adjustSeps
542
543
where
543
- adjustDirectory | FilePath.Posix. hasTrailingPathSeparator path
544
- = FilePath.Windows. addTrailingPathSeparator
545
- | otherwise = id
544
+ adjustSeps = if fromSep == toSep then id else
545
+ map $ \ c -> if c == fromSep then toSep else c
546
+ {-# INLINE fromFilePathInternal #-}
546
547
547
548
--
548
549
-- * Entries type
0 commit comments