Skip to content

Commit 31a707c

Browse files
committed
Merge remote-tracking branch 'github/pr/173'
2 parents 7139cd3 + ec5e8c8 commit 31a707c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

System/FilePath/Internal.hs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ import qualified Data.List as L
120120
#ifndef OS_PATH
121121
import Data.String (fromString)
122122
import System.Environment(getEnv)
123-
import Prelude (String, map, FilePath, Eq, IO, id, last, init, reverse, dropWhile, null, break, takeWhile, take, all, elem, any, head, tail, span)
123+
import Prelude (String, map, FilePath, Eq, IO, id, last, init, reverse, dropWhile, null, break, takeWhile, take, all, elem, any, span)
124124
import Data.Char(toLower, toUpper, isAsciiLower, isAsciiUpper)
125125
import Data.List(stripPrefix, isSuffixOf, uncons)
126126
#define CHAR Char
@@ -672,9 +672,7 @@ hasTrailingPathSeparator x
672672

673673

674674
hasLeadingPathSeparator :: FILEPATH -> Bool
675-
hasLeadingPathSeparator x
676-
| null x = False
677-
| otherwise = isPathSeparator $ head x
675+
hasLeadingPathSeparator = maybe False (isPathSeparator . fst) . uncons
678676

679677

680678
-- | Add a trailing file path separator if one is not already present.
@@ -901,11 +899,21 @@ makeRelative root path
901899
where (a, b) = break isPathSeparator $ dropWhile isPathSeparator x
902900

903901
-- on windows, need to drop '/' which is kind of absolute, but not a drive
904-
dropAbs x | not (null x) && isPathSeparator (head x) && not (hasDrive x) = tail x
905-
dropAbs x = dropDrive x
906-
907-
takeAbs x | not (null x) && isPathSeparator (head x) && not (hasDrive x) = singleton pathSeparator
908-
takeAbs x = map (\y -> if isPathSeparator y then pathSeparator else toLower y) $ takeDrive x
902+
dropAbs x
903+
| Just (hd, tl) <- uncons x
904+
, isPathSeparator hd
905+
, not (hasDrive x)
906+
= tl
907+
| otherwise
908+
= dropDrive x
909+
910+
takeAbs x
911+
| Just (hd, _) <- uncons x
912+
, isPathSeparator hd
913+
, not (hasDrive x)
914+
= singleton pathSeparator
915+
| otherwise
916+
= map (\y -> if isPathSeparator y then pathSeparator else toLower y) $ takeDrive x
909917

910918
-- | Normalise a file
911919
--

0 commit comments

Comments
 (0)