summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-14 13:24:15 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-14 13:24:15 -0400
commit62382fa360e16c83eb33634367ede0b95e467c6e (patch)
tree382d07220dddc8fdcb4543bc25eb26df850e4ca1 /Utility
parent174da3515594fea9ebc1b346d8a52bfd16a443bf (diff)
deal with Cygwin rsync paths issue
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Path.hs24
-rw-r--r--Utility/Rsync.hs15
2 files changed, 36 insertions, 3 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
diff --git a/Utility/Rsync.hs b/Utility/Rsync.hs
index 652da8b20..5f322a0cb 100644
--- a/Utility/Rsync.hs
+++ b/Utility/Rsync.hs
@@ -1,6 +1,6 @@
{- various rsync stuff
-
- - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -49,7 +49,16 @@ rsyncUseDestinationPermissions :: CommandParam
rsyncUseDestinationPermissions = Param "--chmod=ugo=rwX"
rsync :: [CommandParam] -> IO Bool
-rsync = boolSystem "rsync"
+rsync = boolSystem "rsync" . rsyncParamsFixup
+
+{- On Windows, rsync is from Cygwin, and expects to get Cygwin formatted
+ - paths to files. (It thinks that C:foo refers to a host named "C").
+ - Fix up all Files in the Params appropriately. -}
+rsyncParamsFixup :: [CommandParam] -> [CommandParam]
+rsyncParamsFixup = map fixup
+ where
+ fixup (File f) = File (toCygPath f)
+ fixup p = p
{- Runs rsync, but intercepts its progress output and updates a meter.
- The progress output is also output to stdout.
@@ -65,7 +74,7 @@ rsyncProgress meterupdate params = do
reapZombies
return r
where
- p = proc "rsync" (toCommand params)
+ p = proc "rsync" (toCommand $ rsyncParamsFixup params)
feedprogress prev buf h = do
s <- hGetSomeString h 80
if null s