Fixes: debbugs:18623

* net/tramp.el (tramp-handle-insert-file-contents):
Set `find-file-not-found-functions' in case of errors.
This commit is contained in:
Michael Albinus 2014-12-21 12:10:31 +01:00
parent 48a9d9fdbb
commit 74d3b20cf5
2 changed files with 108 additions and 101 deletions

View file

@ -1,3 +1,8 @@
2014-12-21 Michael Albinus <michael.albinus@gmx.de>
* net/tramp.el (tramp-handle-insert-file-contents):
Set `find-file-not-found-functions' in case of errors. (Bug#18623)
2014-12-19 Michael Albinus <michael.albinus@gmx.de> 2014-12-19 Michael Albinus <michael.albinus@gmx.de>
* net/tramp-sh.el (tramp-send-command-and-read): New optional * net/tramp-sh.el (tramp-send-command-and-read): New optional

View file

@ -3086,115 +3086,117 @@ User is always nil."
(setq filename (expand-file-name filename)) (setq filename (expand-file-name filename))
(let (result local-copy remote-copy) (let (result local-copy remote-copy)
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(with-tramp-progress-reporter (unwind-protect
v 3 (format "Inserting `%s'" filename) (if (not (file-exists-p filename))
(unwind-protect (tramp-message v 0 "(New file)")
(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) (with-tramp-progress-reporter
(let (file-name-handler-alist) v 3 (format "Inserting `%s'" filename)
(file-readable-p localname))) (condition-case err
;; Short track: if we are on the local host, we can (if (and (tramp-local-host-p v)
;; run directly. (let (file-name-handler-alist)
(setq result (file-readable-p localname)))
(tramp-run-real-handler ;; Short track: if we are on the local host, we can
'insert-file-contents ;; run directly.
(list localname visit beg end replace))) (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 ;; When we shall insert only a part of the file, we
;; copy this part. This works only for the shell file ;; copy this part. This works only for the shell file
;; name handlers. ;; name handlers.
(when (and (or beg end) (when (and (or beg end)
(tramp-get-method-parameter (tramp-get-method-parameter
(tramp-file-name-method v) 'tramp-login-program)) (tramp-file-name-method v)
(setq remote-copy (tramp-make-tramp-temp-file v)) 'tramp-login-program))
;; This is defined in tramp-sh.el. Let's assume (setq remote-copy (tramp-make-tramp-temp-file v))
;; this is loaded already. ;; This is defined in tramp-sh.el. Let's assume
(tramp-compat-funcall ;; this is loaded already.
'tramp-send-command (tramp-compat-funcall
v 'tramp-send-command
(cond v
((and beg end) (cond
(format "dd bs=1 skip=%d if=%s count=%d of=%s" ((and beg end)
beg (tramp-shell-quote-argument localname) (format "dd bs=1 skip=%d if=%s count=%d of=%s"
(- end beg) remote-copy)) beg (tramp-shell-quote-argument localname)
(beg (- end beg) remote-copy))
(format "dd bs=1 skip=%d if=%s of=%s" (beg
beg (tramp-shell-quote-argument localname) (format "dd bs=1 skip=%d if=%s of=%s"
remote-copy)) beg (tramp-shell-quote-argument localname)
(end remote-copy))
(format "dd bs=1 count=%d if=%s of=%s" (end
end (tramp-shell-quote-argument localname) (format "dd bs=1 count=%d if=%s of=%s"
remote-copy)))) end (tramp-shell-quote-argument localname)
(setq tramp-temp-buffer-file-name nil beg nil end nil)) remote-copy))))
(setq tramp-temp-buffer-file-name nil beg nil end nil))
;; `insert-file-contents-literally' takes care to ;; `insert-file-contents-literally' takes care to
;; avoid calling jka-compr. By let-binding ;; avoid calling jka-compr. By let-binding
;; `inhibit-file-name-operation', we propagate that ;; `inhibit-file-name-operation', we propagate that
;; care to the `file-local-copy' operation. ;; care to the `file-local-copy' operation.
(setq local-copy (setq local-copy
(let ((inhibit-file-name-operation (let ((inhibit-file-name-operation
(when (eq inhibit-file-name-operation (when (eq inhibit-file-name-operation
'insert-file-contents) 'insert-file-contents)
'file-local-copy))) 'file-local-copy)))
(cond (cond
((stringp remote-copy) ((stringp remote-copy)
(file-local-copy (file-local-copy
(tramp-make-tramp-file-name (tramp-make-tramp-file-name
method user host remote-copy))) method user host remote-copy)))
((stringp tramp-temp-buffer-file-name) ((stringp tramp-temp-buffer-file-name)
(copy-file filename tramp-temp-buffer-file-name 'ok) (copy-file
tramp-temp-buffer-file-name) filename tramp-temp-buffer-file-name 'ok)
(t (file-local-copy filename))))) tramp-temp-buffer-file-name)
(t (file-local-copy filename)))))
;; When the file is not readable for the owner, it ;; When the file is not readable for the owner, it
;; cannot be inserted, even if it is readable for the ;; cannot be inserted, even if it is readable for the
;; group or for everybody. ;; group or for everybody.
(set-file-modes (set-file-modes
local-copy (tramp-compat-octal-to-decimal "0600")) local-copy (tramp-compat-octal-to-decimal "0600"))
(when (and (null remote-copy) (when (and (null remote-copy)
(tramp-get-method-parameter (tramp-get-method-parameter
method 'tramp-copy-keep-tmpfile)) method 'tramp-copy-keep-tmpfile))
;; We keep the local file for performance reasons, ;; We keep the local file for performance reasons,
;; useful for "rsync". ;; useful for "rsync".
(setq tramp-temp-buffer-file-name local-copy)) (setq tramp-temp-buffer-file-name local-copy))
;; We must ensure that `file-coding-system-alist' ;; We must ensure that `file-coding-system-alist'
;; matches `local-copy'. We must also use `visit', ;; matches `local-copy'. We must also use `visit',
;; otherwise there might be an error in the ;; otherwise there might be an error in the
;; `revert-buffer' function under XEmacs. ;; `revert-buffer' function under XEmacs.
(let ((file-coding-system-alist (let ((file-coding-system-alist
(tramp-find-file-name-coding-system-alist (tramp-find-file-name-coding-system-alist
filename local-copy))) filename local-copy)))
(setq result (setq result
(insert-file-contents (insert-file-contents
local-copy visit beg end replace))))) 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. ;; Save exit.
(progn (progn
(when visit (when visit
(setq buffer-file-name filename) (setq buffer-file-name filename)
(setq buffer-read-only (not (file-writable-p filename))) (setq buffer-read-only (not (file-writable-p filename)))
(set-visited-file-modtime) (set-visited-file-modtime)
(set-buffer-modified-p nil)) (set-buffer-modified-p nil))
(when (and (stringp local-copy) (when (and (stringp local-copy)
(or remote-copy (null tramp-temp-buffer-file-name))) (or remote-copy (null tramp-temp-buffer-file-name)))
(delete-file local-copy)) (delete-file local-copy))
(when (stringp remote-copy) (when (stringp remote-copy)
(delete-file (delete-file
(tramp-make-tramp-file-name method user host remote-copy))))))) (tramp-make-tramp-file-name method user host remote-copy)))))
;; Result. ;; Result.
(list (expand-file-name filename) (list (expand-file-name filename)
(cadr result)))) (cadr result)))))
(defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix) (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix)
"Like `load' for Tramp files." "Like `load' for Tramp files."