Try again to fix scp escaping.
authorCarl Hetherington <cth@carlh.net>
Fri, 7 Nov 2014 23:52:56 +0000 (23:52 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 7 Nov 2014 23:52:56 +0000 (23:52 +0000)
cdist

diff --git a/cdist b/cdist
index f0e39e797b2250e9658de689a023dd95bc5cfdb6..2be1b0642325fab12c203bca5c761aede2fd275e 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -112,13 +112,22 @@ def log(m):
     if not globals.quiet:
         print '\x1b[33m* %s\x1b[0m' % m
 
+def scp_escape(n):
+    s = n.split(':')
+    assert(len(s) == 1 or len(s) == 2)
+    if len(s) == 2:
+        s[1] = '"\'%s\'"' % s[1]
+        return '%s:%s' % (s[0], s[1])
+    else:
+        return n
+
 def copytree(a, b):
     log('copy %s -> %s' % (a, b))
-    os.system('scp -r "\'%s\'" "\'%s\'"' % (a, b))
+    os.system('scp -r "\'%s\'" "\'%s\'"' % (scp_escape(a), scp_escape(b)))
 
 def copyfile(a, b):
     log('copy %s -> %s' % (a, b))
-    os.system('scp "\'%s\'" "\'%s\'"' % (a, b))
+    os.system('scp "\'%s\'" "\'%s\'"' % (scp_escape(a), scp_escape(b)))
 
 def rmdir(a):
     log('remove %s' % a)