@@ -120,7 +120,7 @@ import qualified Data.List as L
120120#ifndef OS_PATH
121121import Data.String (fromString )
122122import 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 )
124124import Data.Char (toLower , toUpper , isAsciiLower , isAsciiUpper )
125125import Data.List (stripPrefix , isSuffixOf , uncons )
126126#define CHAR Char
@@ -672,9 +672,7 @@ hasTrailingPathSeparator x
672672
673673
674674hasLeadingPathSeparator :: 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