Skip to content

Commit fb39d31

Browse files
committed
Fix quoting problem in Tramp on w32 systems
* lisp/net/tramp-adb.el (tramp-adb-connection-local-default-profile): * lisp/net/tramp-integration.el (tramp-connection-local-default-profile): Revert patch from 2019-05-24. It is fixed differently. * lisp/net/tramp.el (tramp-encoding-shell): (tramp-encoding-command-switch) (tramp-encoding-command-interactive, ) (tramp-unquote-shell-quote-argument): Suppress `shell-file-name'. (tramp-set-file-uid-gid): * lisp/net/tramp-sh.el (tramp-find-inline-compress) (tramp-make-copy-program-file-name): * lisp/net/tramp-smb.el (tramp-smb-handle-copy-directory): Use `tramp-unquote-shell-quote-argument'.
1 parent f2e4c34 commit fb39d31

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

lisp/net/tramp-adb.el

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,11 +1294,8 @@ connection if a previous connection has died for some reason."
12941294

12951295
;; Default settings for connection-local variables.
12961296
(defconst tramp-adb-connection-local-default-profile
1297-
;; `w32-shell-name' is derived from `shell-file-name'. Don't let it
1298-
;; be confused.
1299-
(unless (eq system-type 'windows-nt)
1300-
'((shell-file-name . "/system/bin/sh")
1301-
(shell-command-switch . "-c")))
1297+
'((shell-file-name . "/system/bin/sh")
1298+
(shell-command-switch . "-c"))
13021299
"Default connection-local variables for remote adb connections.")
13031300

13041301
;; `connection-local-set-profile-variables' and

lisp/net/tramp-integration.el

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,8 @@ NAME must be equal to `tramp-current-connection'."
174174
;;; Default connection-local variables for Tramp:
175175

176176
(defconst tramp-connection-local-default-profile
177-
;; `w32-shell-name' is derived from `shell-file-name'. Don't let it
178-
;; be confused.
179-
(unless (eq system-type 'windows-nt)
180-
'((shell-file-name . "/bin/sh")
181-
(shell-command-switch . "-c")))
177+
'((shell-file-name . "/bin/sh")
178+
(shell-command-switch . "-c"))
182179
"Default connection-local variables for remote connections.")
183180

184181
;; `connection-local-set-profile-variables' and

lisp/net/tramp-sh.el

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4578,9 +4578,11 @@ Goes through the list `tramp-inline-compress-commands'."
45784578
;; the pipe symbol be quoted if they use forward
45794579
;; slashes as directory separators.
45804580
(mapconcat
4581-
#'shell-quote-argument (split-string compress) " ")
4581+
#'tramp-unquote-shell-quote-argument
4582+
(split-string compress) " ")
45824583
(mapconcat
4583-
#'shell-quote-argument (split-string decompress) " "))
4584+
#'tramp-unquote-shell-quote-argument
4585+
(split-string decompress) " "))
45844586
nil nil))
45854587
(throw 'next nil))
45864588
(tramp-message
@@ -5282,8 +5284,9 @@ Return ATTR."
52825284
((tramp-get-method-parameter vec 'tramp-remote-copy-program)
52835285
localname)
52845286
((not (zerop (length user)))
5285-
(format "%s@%s:%s" user host (shell-quote-argument localname)))
5286-
(t (format "%s:%s" host (shell-quote-argument localname))))))
5287+
(format
5288+
"%s@%s:%s" user host (tramp-unquote-shell-quote-argument localname)))
5289+
(t (format "%s:%s" host (tramp-unquote-shell-quote-argument localname))))))
52875290

52885291
(defun tramp-method-out-of-band-p (vec size)
52895292
"Return t if this is an out-of-band method, nil otherwise."

lisp/net/tramp-smb.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ pass to the OPERATION."
468468
(append args
469469
(list "-D" (tramp-unquote-shell-quote-argument
470470
localname)
471-
"-c" (shell-quote-argument "tar qc - *")
471+
"-c" (tramp-unquote-shell-quote-argument
472+
"tar qc - *")
472473
"|" "tar" "xfC" "-"
473474
(tramp-unquote-shell-quote-argument
474475
tmpdir)))
@@ -479,7 +480,8 @@ pass to the OPERATION."
479480
args
480481
(list "-D" (tramp-unquote-shell-quote-argument
481482
localname)
482-
"-c" (shell-quote-argument "tar qx -")))))
483+
"-c" (tramp-unquote-shell-quote-argument
484+
"tar qx -")))))
483485

484486
(unwind-protect
485487
(with-temp-buffer

lisp/net/tramp.el

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ This setting has precedence over `auto-save-file-name-transforms'."
135135
:type '(choice (const :tag "Use default" nil)
136136
(directory :tag "Auto save directory name")))
137137

138+
;; Suppress `shell-file-name' for w32 systems.
138139
(defcustom tramp-encoding-shell
139-
(or (tramp-compat-funcall 'w32-shell-name) "/bin/sh")
140+
(let (shell-file-name)
141+
(or (tramp-compat-funcall 'w32-shell-name) "/bin/sh"))
140142
"Use this program for encoding and decoding commands on the local host.
141143
This shell is used to execute the encoding and decoding command on the
142144
local host, so if you want to use `~' in those commands, you should
@@ -159,15 +161,19 @@ use for the remote host."
159161
:group 'tramp
160162
:type '(file :must-match t))
161163

164+
;; Suppress `shell-file-name' for w32 systems.
162165
(defcustom tramp-encoding-command-switch
163-
(if (tramp-compat-funcall 'w32-shell-dos-semantics) "/c" "-c")
166+
(let (shell-file-name)
167+
(if (tramp-compat-funcall 'w32-shell-dos-semantics) "/c" "-c"))
164168
"Use this switch together with `tramp-encoding-shell' for local commands.
165169
See the variable `tramp-encoding-shell' for more information."
166170
:group 'tramp
167171
:type 'string)
168172

173+
;; Suppress `shell-file-name' for w32 systems.
169174
(defcustom tramp-encoding-command-interactive
170-
(unless (tramp-compat-funcall 'w32-shell-dos-semantics) "-i")
175+
(let (shell-file-name)
176+
(unless (tramp-compat-funcall 'w32-shell-dos-semantics) "-i"))
171177
"Use this switch together with `tramp-encoding-shell' for interactive shells.
172178
See the variable `tramp-encoding-shell' for more information."
173179
:version "24.1"
@@ -4391,13 +4397,13 @@ If FILENAME is remote, a file name handler is called."
43914397
(let ((handler (find-file-name-handler filename 'tramp-set-file-uid-gid)))
43924398
(if handler
43934399
(funcall handler #'tramp-set-file-uid-gid filename uid gid)
4394-
;; On W32 "chown" does not work.
4400+
;; On W32 systems, "chown" does not work.
43954401
(unless (memq system-type '(ms-dos windows-nt))
43964402
(let ((uid (or (and (natnump uid) uid) (tramp-get-local-uid 'integer)))
43974403
(gid (or (and (natnump gid) gid) (tramp-get-local-gid 'integer))))
43984404
(tramp-call-process
4399-
nil "chown" nil nil nil
4400-
(format "%d:%d" uid gid) (shell-quote-argument filename)))))))
4405+
nil "chown" nil nil nil (format "%d:%d" uid gid)
4406+
(tramp-unquote-shell-quote-argument filename)))))))
44014407

44024408
(defun tramp-get-local-uid (id-format)
44034409
"The uid of the local user, in ID-FORMAT.
@@ -4815,8 +4821,11 @@ T1 and T2 are time values (as returned by `current-time' for example)."
48154821
(float-time (time-subtract t1 t2)))
48164822

48174823
(defun tramp-unquote-shell-quote-argument (s)
4818-
"Remove quotation prefix \"/:\" from string S, and quote it then for shell."
4819-
(shell-quote-argument (tramp-compat-file-name-unquote s)))
4824+
"Remove quotation prefix \"/:\" from string S, and quote it then for shell.
4825+
Suppress `shell-file-name'. This is needed on w32 systems, which
4826+
would use a wrong quoting for local file names. See `w32-shell-name'."
4827+
(let (shell-file-name)
4828+
(shell-quote-argument (tramp-compat-file-name-unquote s))))
48204829

48214830
;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
48224831
;; does not deal well with newline characters. Newline is replaced by

0 commit comments

Comments
 (0)