summaryrefslogtreecommitdiff
path: root/lisp/net/tramp.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina <fgallina@gnu.org>2014-12-27 13:21:17 -0300
committerFabián Ezequiel Gallina <fgallina@gnu.org>2014-12-27 13:21:17 -0300
commit411c1c65313aa4e22730ba9762e073881f4e299a (patch)
tree14833e398a5ce64db5124afafe992d47e51b70e8 /lisp/net/tramp.el
parentc3c51ec274f423cf8044cd5b9bc0bbc5bda1f6aa (diff)
parent216c6aadf22bfb9d209b6ce9a469499fd6e1b78f (diff)
downloademacs-411c1c65313aa4e22730ba9762e073881f4e299a.tar.gz
Merge from origin/emacs-24
216c6aa * net/tramp-sh.el (tramp-do-copy-or-rename-file-out-of-band): Use `tramp-rsh-end-of-line', it ought to be more robust. 20cfd24 Improve indexing on the chapter/section/subsection levels. 14c3739 * lisp/progmodes/js.el (js-syntax-propertize): "return" can't be divided. ea78112 * net/tramp-sh.el (tramp-do-copy-or-rename-file-out-of-band): Use "\n" as end-of-line delimeter for passwords, when running on MS Windows. 012479a * lisp/progmodes/sh-script.el: Don't set global indent-line-function 75e114f Fix line numbers on Python shell. d0fd23c doc/emacs/buffers.texi (Kill Buffer): Improve indexing. 8e818d1 Keep maximized when going fullscreen. 749813e python.el: Fix electric colon behavior 936d5e5 Fix last patch. 74d3b20 Fixes: debbugs:18623 Conflicts: doc/emacs/ChangeLog doc/lispref/ChangeLog doc/lispref/functions.texi lisp/ChangeLog src/ChangeLog src/xterm.c test/ChangeLog
Diffstat (limited to 'lisp/net/tramp.el')
-rw-r--r--lisp/net/tramp.el261
1 files changed, 133 insertions, 128 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 7aba7494672..dc62ceeceb9 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3086,115 +3086,118 @@ User is always nil."
(setq filename (expand-file-name filename))
(let (result local-copy remote-copy)
(with-parsed-tramp-file-name filename nil
- (with-tramp-progress-reporter
- v 3 (format "Inserting `%s'" filename)
- (unwind-protect
- (if (not (file-exists-p filename))
- (progn
- ;; We don't raise a Tramp error, because it might be
- ;; suppressed, like in `find-file-noselect-1'.
- (tramp-message
- v 1 "File not `%s' found on remote host" filename)
- (signal 'file-error
- (list "File not found on remote host" filename)))
-
- (if (and (tramp-local-host-p v)
- (let (file-name-handler-alist)
- (file-readable-p localname)))
- ;; Short track: if we are on the local host, we can
- ;; run directly.
- (setq result
- (tramp-run-real-handler
- 'insert-file-contents
- (list localname visit beg end replace)))
-
- ;; When we shall insert only a part of the file, we
- ;; copy this part. This works only for the shell file
- ;; name handlers.
- (when (and (or beg end)
- (tramp-get-method-parameter
- (tramp-file-name-method v) 'tramp-login-program))
- (setq remote-copy (tramp-make-tramp-temp-file v))
- ;; This is defined in tramp-sh.el. Let's assume
- ;; this is loaded already.
- (tramp-compat-funcall
- 'tramp-send-command
- v
- (cond
- ((and beg end)
- (format "dd bs=1 skip=%d if=%s count=%d of=%s"
- beg (tramp-shell-quote-argument localname)
- (- end beg) remote-copy))
- (beg
- (format "dd bs=1 skip=%d if=%s of=%s"
- beg (tramp-shell-quote-argument localname)
- remote-copy))
- (end
- (format "dd bs=1 count=%d if=%s of=%s"
- end (tramp-shell-quote-argument localname)
- remote-copy))))
- (setq tramp-temp-buffer-file-name nil beg nil end nil))
-
- ;; `insert-file-contents-literally' takes care to
- ;; avoid calling jka-compr. By let-binding
- ;; `inhibit-file-name-operation', we propagate that
- ;; care to the `file-local-copy' operation.
- (setq local-copy
- (let ((inhibit-file-name-operation
- (when (eq inhibit-file-name-operation
- 'insert-file-contents)
- 'file-local-copy)))
- (cond
- ((stringp remote-copy)
- (file-local-copy
- (tramp-make-tramp-file-name
- method user host remote-copy)))
- ((stringp tramp-temp-buffer-file-name)
- (copy-file filename tramp-temp-buffer-file-name 'ok)
- tramp-temp-buffer-file-name)
- (t (file-local-copy filename)))))
-
- ;; When the file is not readable for the owner, it
- ;; cannot be inserted, even if it is readable for the
- ;; group or for everybody.
- (set-file-modes
- local-copy (tramp-compat-octal-to-decimal "0600"))
-
- (when (and (null remote-copy)
- (tramp-get-method-parameter
- method 'tramp-copy-keep-tmpfile))
- ;; We keep the local file for performance reasons,
- ;; useful for "rsync".
- (setq tramp-temp-buffer-file-name local-copy))
-
- ;; We must ensure that `file-coding-system-alist'
- ;; matches `local-copy'. We must also use `visit',
- ;; otherwise there might be an error in the
- ;; `revert-buffer' function under XEmacs.
- (let ((file-coding-system-alist
- (tramp-find-file-name-coding-system-alist
- filename local-copy)))
- (setq result
- (insert-file-contents
- local-copy visit beg end replace)))))
-
- ;; Save exit.
- (progn
- (when visit
- (setq buffer-file-name filename)
- (setq buffer-read-only (not (file-writable-p filename)))
- (set-visited-file-modtime)
- (set-buffer-modified-p nil))
- (when (and (stringp local-copy)
- (or remote-copy (null tramp-temp-buffer-file-name)))
- (delete-file local-copy))
- (when (stringp remote-copy)
- (delete-file
- (tramp-make-tramp-file-name method user host remote-copy)))))))
-
- ;; Result.
- (list (expand-file-name filename)
- (cadr result))))
+ (unwind-protect
+ (if (not (file-exists-p filename))
+ (tramp-error
+ v 'file-error "File `%s' not found on remote host" filename)
+
+ (with-tramp-progress-reporter
+ v 3 (format "Inserting `%s'" filename)
+ (condition-case err
+ (if (and (tramp-local-host-p v)
+ (let (file-name-handler-alist)
+ (file-readable-p localname)))
+ ;; Short track: if we are on the local host, we can
+ ;; run directly.
+ (setq result
+ (tramp-run-real-handler
+ 'insert-file-contents
+ (list localname visit beg end replace)))
+
+ ;; When we shall insert only a part of the file, we
+ ;; copy this part. This works only for the shell file
+ ;; name handlers.
+ (when (and (or beg end)
+ (tramp-get-method-parameter
+ (tramp-file-name-method v)
+ 'tramp-login-program))
+ (setq remote-copy (tramp-make-tramp-temp-file v))
+ ;; This is defined in tramp-sh.el. Let's assume
+ ;; this is loaded already.
+ (tramp-compat-funcall
+ 'tramp-send-command
+ v
+ (cond
+ ((and beg end)
+ (format "dd bs=1 skip=%d if=%s count=%d of=%s"
+ beg (tramp-shell-quote-argument localname)
+ (- end beg) remote-copy))
+ (beg
+ (format "dd bs=1 skip=%d if=%s of=%s"
+ beg (tramp-shell-quote-argument localname)
+ remote-copy))
+ (end
+ (format "dd bs=1 count=%d if=%s of=%s"
+ end (tramp-shell-quote-argument localname)
+ remote-copy))))
+ (setq tramp-temp-buffer-file-name nil beg nil end nil))
+
+ ;; `insert-file-contents-literally' takes care to
+ ;; avoid calling jka-compr. By let-binding
+ ;; `inhibit-file-name-operation', we propagate that
+ ;; care to the `file-local-copy' operation.
+ (setq local-copy
+ (let ((inhibit-file-name-operation
+ (when (eq inhibit-file-name-operation
+ 'insert-file-contents)
+ 'file-local-copy)))
+ (cond
+ ((stringp remote-copy)
+ (file-local-copy
+ (tramp-make-tramp-file-name
+ method user host remote-copy)))
+ ((stringp tramp-temp-buffer-file-name)
+ (copy-file
+ filename tramp-temp-buffer-file-name 'ok)
+ tramp-temp-buffer-file-name)
+ (t (file-local-copy filename)))))
+
+ ;; When the file is not readable for the owner, it
+ ;; cannot be inserted, even if it is readable for the
+ ;; group or for everybody.
+ (set-file-modes
+ local-copy (tramp-compat-octal-to-decimal "0600"))
+
+ (when (and (null remote-copy)
+ (tramp-get-method-parameter
+ method 'tramp-copy-keep-tmpfile))
+ ;; We keep the local file for performance reasons,
+ ;; useful for "rsync".
+ (setq tramp-temp-buffer-file-name local-copy))
+
+ ;; We must ensure that `file-coding-system-alist'
+ ;; matches `local-copy'. We must also use `visit',
+ ;; otherwise there might be an error in the
+ ;; `revert-buffer' function under XEmacs.
+ (let ((file-coding-system-alist
+ (tramp-find-file-name-coding-system-alist
+ filename local-copy)))
+ (setq result
+ (insert-file-contents
+ local-copy visit beg end replace))))
+ (error
+ (add-hook 'find-file-not-found-functions
+ `(lambda () (signal ',(car err) ',(cdr err)))
+ nil t)
+ (signal (car err) (cdr err))))))
+
+ ;; Save exit.
+ (progn
+ (when visit
+ (setq buffer-file-name filename)
+ (setq buffer-read-only (not (file-writable-p filename)))
+ (set-visited-file-modtime)
+ (set-buffer-modified-p nil))
+ (when (and (stringp local-copy)
+ (or remote-copy (null tramp-temp-buffer-file-name)))
+ (delete-file local-copy))
+ (when (stringp remote-copy)
+ (delete-file
+ (tramp-make-tramp-file-name method user host remote-copy)))))
+
+ ;; Result.
+ (list (expand-file-name filename)
+ (cadr result)))))
(defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix)
"Like `load' for Tramp files."
@@ -4188,25 +4191,27 @@ Invokes `password-read' if available, `read-passwd' else."
;; it's bound. `auth-source-user-or-password' is an
;; obsoleted function, it has been replaced by
;; `auth-source-search'.
- (and (boundp 'auth-sources)
- (tramp-get-connection-property
- v "first-password-request" nil)
- ;; Try with Tramp's current method.
- (if (fboundp 'auth-source-search)
- (setq auth-info
- (tramp-compat-funcall
- 'auth-source-search
- :max 1
- :user (or tramp-current-user t)
- :host tramp-current-host
- :port tramp-current-method)
- auth-passwd (plist-get (nth 0 auth-info) :secret)
- auth-passwd (if (functionp auth-passwd)
- (funcall auth-passwd)
- auth-passwd))
- (tramp-compat-funcall
- 'auth-source-user-or-password
- "password" tramp-current-host tramp-current-method)))
+ (ignore-errors
+ (and (boundp 'auth-sources)
+ (tramp-get-connection-property
+ v "first-password-request" nil)
+ ;; Try with Tramp's current method.
+ (if (fboundp 'auth-source-search)
+ (setq auth-info
+ (tramp-compat-funcall
+ 'auth-source-search
+ :max 1
+ :user (or tramp-current-user t)
+ :host tramp-current-host
+ :port tramp-current-method)
+ auth-passwd (plist-get
+ (nth 0 auth-info) :secret)
+ auth-passwd (if (functionp auth-passwd)
+ (funcall auth-passwd)
+ auth-passwd))
+ (tramp-compat-funcall
+ 'auth-source-user-or-password
+ "password" tramp-current-host tramp-current-method))))
;; Try the password cache.
(when (functionp 'password-read)
(let ((password