aboutsummaryrefslogtreecommitdiff
path: root/Utility/Path.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r--Utility/Path.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/Utility/Path.hs b/Utility/Path.hs
index 2c2fc35ff..09cf739dc 100644
--- a/Utility/Path.hs
+++ b/Utility/Path.hs
@@ -17,6 +17,11 @@ import Data.List
import Data.Maybe
import Control.Applicative
+#ifdef __WINDOWS__
+import Data.Char
+import System.FilePath.Posix as Posix
+#endif
+
import Utility.Monad
import Utility.UserInfo
@@ -185,3 +190,22 @@ dotfile file
| otherwise = "." `isPrefixOf` f || dotfile (takeDirectory file)
where
f = takeFileName file
+
+{- Converts a DOS style path to a Cygwin style path. Only on Windows.
+ - Any trailing '\' is preserved as a trailing '/' -}
+toCygPath :: FilePath -> FilePath
+#ifndef __WINDOWS__
+toCygPath = id
+#else
+toCygPath p
+ | null drive = recombine parts
+ | otherwise = recombine $ "/cygdrive" : driveletter drive : parts
+ where
+ (drive, p') = splitDrive p
+ parts = splitDirectories p'
+ driveletter = map toLower . takeWhile (/= ':')
+ recombine = fixtrailing . Posix.joinPath
+ fixtrailing s
+ | hasTrailingPathSeparator p = Posix.addTrailingPathSeparator s
+ | otherwise = s
+#endif