diff options
author | Joey Hess <joey@kitenet.net> | 2013-05-14 13:24:15 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-05-14 13:24:15 -0400 |
commit | 62382fa360e16c83eb33634367ede0b95e467c6e (patch) | |
tree | 382d07220dddc8fdcb4543bc25eb26df850e4ca1 /Utility/Path.hs | |
parent | 174da3515594fea9ebc1b346d8a52bfd16a443bf (diff) |
deal with Cygwin rsync paths issue
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r-- | Utility/Path.hs | 24 |
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 |