From 1326bb863516b5e7efbfd9fba2754a3fe7289315 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 18 Nov 2011 12:53:48 -0400 Subject: Avoid excessive escaping for rsync special remotes that are not accessed over ssh. This is actually tricky, 45bbf210a1210172c7c7b87879ed74f7c8ccbdba added the escaping because it's needed for rsync that does go over ssh. So I had to detect whether the remote's rsync url will use ssh or not, and vary the escaping. --- Remote/Rsync.hs | 9 +++++++-- Utility/RsyncFile.hs | 16 ++++++++++++++++ debian/changelog | 2 ++ .../extraneous_shell_escaping_for_rsync_remotes.mdwn | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Remote/Rsync.hs b/Remote/Rsync.hs index 86ff2ea5b..5cd27a609 100644 --- a/Remote/Rsync.hs +++ b/Remote/Rsync.hs @@ -81,13 +81,18 @@ rsyncSetup u c = do gitConfigSpecialRemote u c' "rsyncurl" url return c' +rsyncEscape :: RsyncOpts -> String -> String +rsyncEscape o s + | rsyncUrlIsShell (rsyncUrl o) = shellEscape s + | otherwise = s + rsyncKey :: RsyncOpts -> Key -> String -rsyncKey o k = rsyncUrl o hashDirMixed k shellEscape (f f) +rsyncKey o k = rsyncUrl o hashDirMixed k rsyncEscape o (f f) where f = keyFile k rsyncKeyDir :: RsyncOpts -> Key -> String -rsyncKeyDir o k = rsyncUrl o hashDirMixed k shellEscape (keyFile k) +rsyncKeyDir o k = rsyncUrl o hashDirMixed k rsyncEscape o (keyFile k) store :: RsyncOpts -> Key -> Annex Bool store o k = rsyncSend o k =<< fromRepo (gitAnnexLocation k) diff --git a/Utility/RsyncFile.hs b/Utility/RsyncFile.hs index c5006a30f..a691d0a0e 100644 --- a/Utility/RsyncFile.hs +++ b/Utility/RsyncFile.hs @@ -8,6 +8,7 @@ module Utility.RsyncFile where import Data.String.Utils +import Data.List import Utility.SafeCommand @@ -48,3 +49,18 @@ rsync = boolSystem "rsync" rsyncExec :: [CommandParam] -> IO () rsyncExec params = executeFile "rsync" True (toCommand params) Nothing + +{- Checks if an rsync url involves the remote shell (ssh or rsh). + - Use of such urls with rsync or rsyncExec requires additional shell + - escaping. -} +rsyncUrlIsShell :: String -> Bool +rsyncUrlIsShell s + | "rsync://" `isPrefixOf` s = False + | otherwise = go s + where + -- host:dir is rsync protocol, while host:dir is ssh/rsh + go [] = False + go (c:cs) + | c == '/' = False -- got to directory with no colon + | c == ':' = not $ ":" `isPrefixOf` cs + | otherwise = go cs diff --git a/debian/changelog b/debian/changelog index 6976fd13a..52d08f303 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,8 @@ git-annex (3.20111112) UNRELEASED; urgency=low * When not run in a git repository, git-annex can still display a usage message, and "git annex version" even works. * migrate: Don't fall over a stale temp file. + * Avoid excessive escaping for rsync special remotes that are not accessed + over ssh. -- Joey Hess Sat, 12 Nov 2011 14:50:21 -0400 diff --git a/doc/bugs/extraneous_shell_escaping_for_rsync_remotes.mdwn b/doc/bugs/extraneous_shell_escaping_for_rsync_remotes.mdwn index 0b292c5c9..c4ee8d5bd 100644 --- a/doc/bugs/extraneous_shell_escaping_for_rsync_remotes.mdwn +++ b/doc/bugs/extraneous_shell_escaping_for_rsync_remotes.mdwn @@ -11,3 +11,5 @@ I attached a patch for this. > > Ah, you're not using rsync over ssh, but just to a local directory, > right? --[[Joey]] + +>> [[fixed|done]] --[[Joey]] -- cgit v1.2.3