comparison lisp/net/tramp-cmds.el @ 85694:21983e7c844a

* net/tramp.el (tramp-wrong-passwd-regexp): Tune regexp. (tramp-get-remote-tmpdir): New defun. (tramp-make-tramp-temp-file): Use it. (tramp-local-call-process): New defun. Replace all calls of `call-process' by this when appropriate. (tramp-handle-write-region): Replace calls of `file-attributes' by `tramp-compat-file-attributes'. (tramp-find-shell, tramp-open-connection-setup-interactive-shell): Make the first command a `tramp-send-command' call, with let-bind of `tramp-end-of-output'. (tramp-version, tramp-bug, tramp-reporter-dump-variable) (tramp-load-report-modules, tramp-append-tramp-buffers): Move to tramp-cmds.el. * net/tramp-fish.el (tramp-fish-handle-copy-file) (tramp-fish-do-copy-or-rename-file) (tramp-fish-do-copy-or-rename-file-directly): * net/tramp-smb.el (tramp-smb-handle-copy-file): Add parameter PRESERVE-UID-GID.
author Michael Albinus <michael.albinus@gmx.de>
date Sat, 27 Oct 2007 13:57:43 +0000
parents 1ee7c459e1db
children 85b6f7d4aca8
comparison
equal deleted inserted replaced
85693:dbd6dad40424 85694:21983e7c844a
123 123
124 ;; Remove all buffers with a remote default-directory. 124 ;; Remove all buffers with a remote default-directory.
125 (dolist (name (tramp-list-remote-buffers)) 125 (dolist (name (tramp-list-remote-buffers))
126 (when (bufferp (get-buffer name)) (kill-buffer name)))) 126 (when (bufferp (get-buffer name)) (kill-buffer name))))
127 127
128 ;; Tramp version is useful in a number of situations.
129
130 (defun tramp-version (arg)
131 "Print version number of tramp.el in minibuffer or current buffer."
132 (interactive "P")
133 (if arg (insert tramp-version) (message tramp-version)))
134
135 ;; Make the `reporter` functionality available for making bug reports about
136 ;; the package. A most useful piece of code.
137
138 (autoload 'reporter-submit-bug-report "reporter")
139
140 (defun tramp-bug ()
141 "Submit a bug report to the Tramp developers."
142 (interactive)
143 (require 'reporter)
144 (catch 'dont-send
145 (let ((reporter-prompt-for-summary-p t))
146 (reporter-submit-bug-report
147 tramp-bug-report-address ; to-address
148 (format "tramp (%s)" tramp-version) ; package name and version
149 (delq nil
150 `(;; Current state
151 tramp-current-method
152 tramp-current-user
153 tramp-current-host
154
155 ;; System defaults
156 tramp-auto-save-directory ; vars to dump
157 tramp-default-method
158 tramp-default-method-alist
159 tramp-default-host
160 tramp-default-proxies-alist
161 tramp-default-user
162 tramp-default-user-alist
163 tramp-rsh-end-of-line
164 tramp-default-password-end-of-line
165 tramp-login-prompt-regexp
166 ;; Mask non-7bit characters
167 (tramp-password-prompt-regexp . tramp-reporter-dump-variable)
168 tramp-wrong-passwd-regexp
169 tramp-yesno-prompt-regexp
170 tramp-yn-prompt-regexp
171 tramp-terminal-prompt-regexp
172 tramp-temp-name-prefix
173 tramp-file-name-structure
174 tramp-file-name-regexp
175 tramp-methods
176 tramp-end-of-output
177 tramp-local-coding-commands
178 tramp-remote-coding-commands
179 tramp-actions-before-shell
180 tramp-actions-copy-out-of-band
181 tramp-terminal-type
182 ;; Mask non-7bit characters
183 (tramp-shell-prompt-pattern . tramp-reporter-dump-variable)
184 ,(when (boundp 'tramp-backup-directory-alist)
185 'tramp-backup-directory-alist)
186 ,(when (boundp 'tramp-bkup-backup-directory-info)
187 'tramp-bkup-backup-directory-info)
188 ;; Dump cache.
189 (tramp-cache-data . tramp-reporter-dump-variable)
190
191 ;; Non-tramp variables of interest
192 ;; Mask non-7bit characters
193 (shell-prompt-pattern . tramp-reporter-dump-variable)
194 backup-by-copying
195 backup-by-copying-when-linked
196 backup-by-copying-when-mismatch
197 ,(when (boundp 'backup-by-copying-when-privileged-mismatch)
198 'backup-by-copying-when-privileged-mismatch)
199 ,(when (boundp 'password-cache)
200 'password-cache)
201 ,(when (boundp 'password-cache-expiry)
202 'password-cache-expiry)
203 ,(when (boundp 'backup-directory-alist)
204 'backup-directory-alist)
205 ,(when (boundp 'bkup-backup-directory-info)
206 'bkup-backup-directory-info)
207 file-name-handler-alist))
208
209 'tramp-load-report-modules ; pre-hook
210 'tramp-append-tramp-buffers ; post-hook
211 "\
212 Enter your bug report in this message, including as much detail
213 as you possibly can about the problem, what you did to cause it
214 and what the local and remote machines are.
215
216 If you can give a simple set of instructions to make this bug
217 happen reliably, please include those. Thank you for helping
218 kill bugs in Tramp.
219
220 Another useful thing to do is to put
221
222 (setq tramp-verbose 8)
223
224 in the ~/.emacs file and to repeat the bug. Then, include the
225 contents of the *tramp/foo* buffer and the *debug tramp/foo*
226 buffer in your bug report.
227
228 --bug report follows this line--
229 "))))
230
231 (defun tramp-reporter-dump-variable (varsym mailbuf)
232 "Pretty-print the value of the variable in symbol VARSYM.
233 Used for non-7bit chars in strings."
234 (let* ((reporter-eval-buffer (symbol-value 'reporter-eval-buffer))
235 (val (with-current-buffer reporter-eval-buffer
236 (symbol-value varsym))))
237
238 (if (hash-table-p val)
239 ;; Pretty print the cache.
240 (set varsym (read (format "(%s)" (tramp-cache-print val))))
241 ;; There are characters to be masked.
242 (when (and (boundp 'mm-7bit-chars)
243 (string-match
244 (concat "[^" (symbol-value 'mm-7bit-chars) "]") val))
245 (with-current-buffer reporter-eval-buffer
246 (set varsym (format "(base64-decode-string \"%s\""
247 (base64-encode-string val))))))
248
249 ;; Dump variable.
250 (funcall (symbol-function 'reporter-dump-variable) varsym mailbuf)
251
252 (unless (hash-table-p val)
253 ;; Remove string quotation.
254 (forward-line -1)
255 (when (looking-at
256 (concat "\\(^.*\\)" "\"" ;; \1 "
257 "\\((base64-decode-string \\)" "\\\\" ;; \2 \
258 "\\(\".*\\)" "\\\\" ;; \3 \
259 "\\(\")\\)" "\"$")) ;; \4 "
260 (replace-match "\\1\\2\\3\\4")
261 (beginning-of-line)
262 (insert " ;; variable encoded due to non-printable characters\n"))
263 (forward-line 1))
264
265 ;; Reset VARSYM to old value.
266 (with-current-buffer reporter-eval-buffer
267 (set varsym val))))
268
269 (defun tramp-load-report-modules ()
270 "Load needed modules for reporting."
271
272 ;; We load message.el and mml.el from Gnus.
273 (if (featurep 'xemacs)
274 (progn
275 (load "message" 'noerror)
276 (load "mml" 'noerror))
277 (require 'message nil 'noerror)
278 (require 'mml nil 'noerror))
279 (when (functionp 'message-mode)
280 (funcall (symbol-function 'message-mode)))
281 (when (functionp 'mml-mode)
282 (funcall (symbol-function 'mml-mode) t)))
283
284 (defun tramp-append-tramp-buffers ()
285 "Append Tramp buffers and buffer local variables into the bug report."
286
287 (goto-char (point-max))
288
289 ;; Dump buffer local variables.
290 (dolist (buffer
291 (delq nil
292 (mapcar
293 '(lambda (b)
294 (when (string-match "\\*tramp/" (buffer-name b)) b))
295 (buffer-list))))
296 (let ((reporter-eval-buffer buffer)
297 (buffer-name (buffer-name buffer))
298 (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
299 (with-current-buffer elbuf
300 (emacs-lisp-mode)
301 (erase-buffer)
302 (insert "\n(setq\n")
303 (lisp-indent-line)
304 (funcall (symbol-function 'reporter-dump-variable)
305 'buffer-name (current-buffer))
306 (dolist (varsym-or-cons-cell (buffer-local-variables buffer))
307 (let ((varsym (or (car-safe varsym-or-cons-cell)
308 varsym-or-cons-cell)))
309 (when (string-match "tramp" (symbol-name varsym))
310 (funcall
311 (symbol-function 'reporter-dump-variable)
312 varsym (current-buffer)))))
313 (lisp-indent-line)
314 (insert ")\n"))
315 (insert-buffer-substring elbuf)))
316
317 ;; Append buffers only when we are in message mode.
318 (when (and
319 (eq major-mode 'message-mode)
320 (boundp 'mml-mode)
321 (symbol-value 'mml-mode))
322
323 (let ((tramp-buf-regexp "\\*\\(debug \\)?tramp/")
324 (buffer-list (funcall (symbol-function 'tramp-list-tramp-buffers)))
325 (curbuf (current-buffer)))
326
327 ;; There is at least one Tramp buffer.
328 (when buffer-list
329 (switch-to-buffer (list-buffers-noselect nil))
330 (delete-other-windows)
331 (setq buffer-read-only nil)
332 (goto-char (point-min))
333 (while (not (eobp))
334 (if (re-search-forward
335 tramp-buf-regexp (tramp-compat-line-end-position) t)
336 (forward-line 1)
337 (forward-line 0)
338 (let ((start (point)))
339 (forward-line 1)
340 (kill-region start (point)))))
341 (insert "
342 The buffer(s) above will be appended to this message. If you
343 don't want to append a buffer because it contains sensitive data,
344 or because the buffer is too large, you should delete the
345 respective buffer. The buffer(s) will contain user and host
346 names. Passwords will never be included there.")
347
348 (when (>= tramp-verbose 6)
349 (insert "\n\n")
350 (let ((start (point)))
351 (insert "\
352 Please note that you have set `tramp-verbose' to a value of at
353 least 6. Therefore, the contents of files might be included in
354 the debug buffer(s).")
355 (add-text-properties start (point) (list 'face 'italic))))
356
357 (set-buffer-modified-p nil)
358 (setq buffer-read-only t)
359 (goto-char (point-min))
360
361 (if (y-or-n-p "Do you want to append the buffer(s)? ")
362 ;; OK, let's send. First we delete the buffer list.
363 (progn
364 (kill-buffer nil)
365 (switch-to-buffer curbuf)
366 (goto-char (point-max))
367 (insert "\n\
368 This is a special notion of the `gnus/message' package. If you
369 use another mail agent (by copying the contents of this buffer)
370 please ensure that the buffers are attached to your email.\n\n")
371 (dolist (buffer buffer-list)
372 (funcall (symbol-function 'mml-insert-empty-tag)
373 'part 'type "text/plain" 'encoding "base64"
374 'disposition "attachment" 'buffer buffer
375 'description buffer))
376 (set-buffer-modified-p nil))
377
378 ;; Don't send. Delete the message buffer.
379 (set-buffer curbuf)
380 (set-buffer-modified-p nil)
381 (kill-buffer nil)
382 (throw 'dont-send nil))))))
383
384 (defalias 'tramp-submit-bug 'tramp-bug)
385
128 (provide 'tramp-cmds) 386 (provide 'tramp-cmds)
129 387
130 ;;; TODO: 388 ;;; TODO:
131 389
132 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman) 390 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
133 ;; * WIBNI there was an interactive command prompting for tramp 391 ;; * WIBNI there was an interactive command prompting for Tramp
134 ;; method, hostname, username and filename and translates the user 392 ;; method, hostname, username and filename and translates the user
135 ;; input into the correct filename syntax (depending on the Emacs 393 ;; input into the correct filename syntax (depending on the Emacs
136 ;; flavor) (Reiner Steib) 394 ;; flavor) (Reiner Steib)
137 ;; * Let the user edit the connection properties interactively. 395 ;; * Let the user edit the connection properties interactively.
138 ;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer. 396 ;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer.