diff options
| author | Michael Albinus | 2014-12-21 12:10:31 +0100 |
|---|---|---|
| committer | Michael Albinus | 2014-12-21 12:10:31 +0100 |
| commit | 74d3b20cf5fb4fe863a97379dea26412b27d7f39 (patch) | |
| tree | ed75bbf938df71beb4cc9865dddfa913a9bdab46 | |
| parent | 48a9d9fdbbe8946ae29393ee8bc24c6f6619003c (diff) | |
| download | emacs-74d3b20cf5fb4fe863a97379dea26412b27d7f39.tar.gz emacs-74d3b20cf5fb4fe863a97379dea26412b27d7f39.zip | |
Fixes: debbugs:18623
* net/tramp.el (tramp-handle-insert-file-contents):
Set `find-file-not-found-functions' in case of errors.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 220 |
2 files changed, 116 insertions, 109 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ed08c9fbdbb..e4f620ecb40 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-12-21 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * net/tramp.el (tramp-handle-insert-file-contents): | ||
| 4 | Set `find-file-not-found-functions' in case of errors. (Bug#18623) | ||
| 5 | |||
| 1 | 2014-12-19 Michael Albinus <michael.albinus@gmx.de> | 6 | 2014-12-19 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 7 | ||
| 3 | * net/tramp-sh.el (tramp-send-command-and-read): New optional | 8 | * net/tramp-sh.el (tramp-send-command-and-read): New optional |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 140bf1874bf..fdb00c813d6 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -3086,115 +3086,117 @@ User is always nil." | |||
| 3086 | (setq filename (expand-file-name filename)) | 3086 | (setq filename (expand-file-name filename)) |
| 3087 | (let (result local-copy remote-copy) | 3087 | (let (result local-copy remote-copy) |
| 3088 | (with-parsed-tramp-file-name filename nil | 3088 | (with-parsed-tramp-file-name filename nil |
| 3089 | (with-tramp-progress-reporter | 3089 | (unwind-protect |
| 3090 | v 3 (format "Inserting `%s'" filename) | 3090 | (if (not (file-exists-p filename)) |
| 3091 | (unwind-protect | 3091 | (tramp-message v 0 "(New file)") |
| 3092 | (if (not (file-exists-p filename)) | 3092 | |
| 3093 | (progn | 3093 | (with-tramp-progress-reporter |
| 3094 | ;; We don't raise a Tramp error, because it might be | 3094 | v 3 (format "Inserting `%s'" filename) |
| 3095 | ;; suppressed, like in `find-file-noselect-1'. | 3095 | (condition-case err |
| 3096 | (tramp-message | 3096 | (if (and (tramp-local-host-p v) |
| 3097 | v 1 "File not `%s' found on remote host" filename) | 3097 | (let (file-name-handler-alist) |
| 3098 | (signal 'file-error | 3098 | (file-readable-p localname))) |
| 3099 | (list "File not found on remote host" filename))) | 3099 | ;; Short track: if we are on the local host, we can |
| 3100 | 3100 | ;; run directly. | |
| 3101 | (if (and (tramp-local-host-p v) | 3101 | (setq result |
| 3102 | (let (file-name-handler-alist) | 3102 | (tramp-run-real-handler |
| 3103 | (file-readable-p localname))) | 3103 | 'insert-file-contents |
| 3104 | ;; Short track: if we are on the local host, we can | 3104 | (list localname visit beg end replace))) |
| 3105 | ;; run directly. | 3105 | |
| 3106 | (setq result | 3106 | ;; When we shall insert only a part of the file, we |
| 3107 | (tramp-run-real-handler | 3107 | ;; copy this part. This works only for the shell file |
| 3108 | 'insert-file-contents | 3108 | ;; name handlers. |
| 3109 | (list localname visit beg end replace))) | 3109 | (when (and (or beg end) |
| 3110 | 3110 | (tramp-get-method-parameter | |
| 3111 | ;; When we shall insert only a part of the file, we | 3111 | (tramp-file-name-method v) |
| 3112 | ;; copy this part. This works only for the shell file | 3112 | 'tramp-login-program)) |
| 3113 | ;; name handlers. | 3113 | (setq remote-copy (tramp-make-tramp-temp-file v)) |
| 3114 | (when (and (or beg end) | 3114 | ;; This is defined in tramp-sh.el. Let's assume |
| 3115 | (tramp-get-method-parameter | 3115 | ;; this is loaded already. |
| 3116 | (tramp-file-name-method v) 'tramp-login-program)) | 3116 | (tramp-compat-funcall |
| 3117 | (setq remote-copy (tramp-make-tramp-temp-file v)) | 3117 | 'tramp-send-command |
| 3118 | ;; This is defined in tramp-sh.el. Let's assume | 3118 | v |
| 3119 | ;; this is loaded already. | 3119 | (cond |
| 3120 | (tramp-compat-funcall | 3120 | ((and beg end) |
| 3121 | 'tramp-send-command | 3121 | (format "dd bs=1 skip=%d if=%s count=%d of=%s" |
| 3122 | v | 3122 | beg (tramp-shell-quote-argument localname) |
| 3123 | (cond | 3123 | (- end beg) remote-copy)) |
| 3124 | ((and beg end) | 3124 | (beg |
| 3125 | (format "dd bs=1 skip=%d if=%s count=%d of=%s" | 3125 | (format "dd bs=1 skip=%d if=%s of=%s" |
| 3126 | beg (tramp-shell-quote-argument localname) | 3126 | beg (tramp-shell-quote-argument localname) |
| 3127 | (- end beg) remote-copy)) | 3127 | remote-copy)) |
| 3128 | (beg | 3128 | (end |
| 3129 | (format "dd bs=1 skip=%d if=%s of=%s" | 3129 | (format "dd bs=1 count=%d if=%s of=%s" |
| 3130 | beg (tramp-shell-quote-argument localname) | 3130 | end (tramp-shell-quote-argument localname) |
| 3131 | remote-copy)) | 3131 | remote-copy)))) |
| 3132 | (end | 3132 | (setq tramp-temp-buffer-file-name nil beg nil end nil)) |
| 3133 | (format "dd bs=1 count=%d if=%s of=%s" | 3133 | |
| 3134 | end (tramp-shell-quote-argument localname) | 3134 | ;; `insert-file-contents-literally' takes care to |
| 3135 | remote-copy)))) | 3135 | ;; avoid calling jka-compr. By let-binding |
| 3136 | (setq tramp-temp-buffer-file-name nil beg nil end nil)) | 3136 | ;; `inhibit-file-name-operation', we propagate that |
| 3137 | 3137 | ;; care to the `file-local-copy' operation. | |
| 3138 | ;; `insert-file-contents-literally' takes care to | 3138 | (setq local-copy |
| 3139 | ;; avoid calling jka-compr. By let-binding | 3139 | (let ((inhibit-file-name-operation |
| 3140 | ;; `inhibit-file-name-operation', we propagate that | 3140 | (when (eq inhibit-file-name-operation |
| 3141 | ;; care to the `file-local-copy' operation. | 3141 | 'insert-file-contents) |
| 3142 | (setq local-copy | 3142 | 'file-local-copy))) |
| 3143 | (let ((inhibit-file-name-operation | 3143 | (cond |
| 3144 | (when (eq inhibit-file-name-operation | 3144 | ((stringp remote-copy) |
| 3145 | 'insert-file-contents) | 3145 | (file-local-copy |
| 3146 | 'file-local-copy))) | 3146 | (tramp-make-tramp-file-name |
| 3147 | (cond | 3147 | method user host remote-copy))) |
| 3148 | ((stringp remote-copy) | 3148 | ((stringp tramp-temp-buffer-file-name) |
| 3149 | (file-local-copy | 3149 | (copy-file |
| 3150 | (tramp-make-tramp-file-name | 3150 | filename tramp-temp-buffer-file-name 'ok) |
| 3151 | method user host remote-copy))) | 3151 | tramp-temp-buffer-file-name) |
| 3152 | ((stringp tramp-temp-buffer-file-name) | 3152 | (t (file-local-copy filename))))) |
| 3153 | (copy-file filename tramp-temp-buffer-file-name 'ok) | 3153 | |
| 3154 | tramp-temp-buffer-file-name) | 3154 | ;; When the file is not readable for the owner, it |
| 3155 | (t (file-local-copy filename))))) | 3155 | ;; cannot be inserted, even if it is readable for the |
| 3156 | 3156 | ;; group or for everybody. | |
| 3157 | ;; When the file is not readable for the owner, it | 3157 | (set-file-modes |
| 3158 | ;; cannot be inserted, even if it is readable for the | 3158 | local-copy (tramp-compat-octal-to-decimal "0600")) |
| 3159 | ;; group or for everybody. | 3159 | |
| 3160 | (set-file-modes | 3160 | (when (and (null remote-copy) |
| 3161 | local-copy (tramp-compat-octal-to-decimal "0600")) | 3161 | (tramp-get-method-parameter |
| 3162 | 3162 | method 'tramp-copy-keep-tmpfile)) | |
| 3163 | (when (and (null remote-copy) | 3163 | ;; We keep the local file for performance reasons, |
| 3164 | (tramp-get-method-parameter | 3164 | ;; useful for "rsync". |
| 3165 | method 'tramp-copy-keep-tmpfile)) | 3165 | (setq tramp-temp-buffer-file-name local-copy)) |
| 3166 | ;; We keep the local file for performance reasons, | 3166 | |
| 3167 | ;; useful for "rsync". | 3167 | ;; We must ensure that `file-coding-system-alist' |
| 3168 | (setq tramp-temp-buffer-file-name local-copy)) | 3168 | ;; matches `local-copy'. We must also use `visit', |
| 3169 | 3169 | ;; otherwise there might be an error in the | |
| 3170 | ;; We must ensure that `file-coding-system-alist' | 3170 | ;; `revert-buffer' function under XEmacs. |
| 3171 | ;; matches `local-copy'. We must also use `visit', | 3171 | (let ((file-coding-system-alist |
| 3172 | ;; otherwise there might be an error in the | 3172 | (tramp-find-file-name-coding-system-alist |
| 3173 | ;; `revert-buffer' function under XEmacs. | 3173 | filename local-copy))) |
| 3174 | (let ((file-coding-system-alist | 3174 | (setq result |
| 3175 | (tramp-find-file-name-coding-system-alist | 3175 | (insert-file-contents |
| 3176 | filename local-copy))) | 3176 | local-copy visit beg end replace)))) |
| 3177 | (setq result | 3177 | (error |
| 3178 | (insert-file-contents | 3178 | (add-hook 'find-file-not-found-functions |
| 3179 | local-copy visit beg end replace))))) | 3179 | `(lambda () (signal ',(car err) ',(cdr err))) |
| 3180 | 3180 | nil t) | |
| 3181 | ;; Save exit. | 3181 | (signal (car err) (cdr err)))))) |
| 3182 | (progn | 3182 | |
| 3183 | (when visit | 3183 | ;; Save exit. |
| 3184 | (setq buffer-file-name filename) | 3184 | (progn |
| 3185 | (setq buffer-read-only (not (file-writable-p filename))) | 3185 | (when visit |
| 3186 | (set-visited-file-modtime) | 3186 | (setq buffer-file-name filename) |
| 3187 | (set-buffer-modified-p nil)) | 3187 | (setq buffer-read-only (not (file-writable-p filename))) |
| 3188 | (when (and (stringp local-copy) | 3188 | (set-visited-file-modtime) |
| 3189 | (or remote-copy (null tramp-temp-buffer-file-name))) | 3189 | (set-buffer-modified-p nil)) |
| 3190 | (delete-file local-copy)) | 3190 | (when (and (stringp local-copy) |
| 3191 | (when (stringp remote-copy) | 3191 | (or remote-copy (null tramp-temp-buffer-file-name))) |
| 3192 | (delete-file | 3192 | (delete-file local-copy)) |
| 3193 | (tramp-make-tramp-file-name method user host remote-copy))))))) | 3193 | (when (stringp remote-copy) |
| 3194 | 3194 | (delete-file | |
| 3195 | ;; Result. | 3195 | (tramp-make-tramp-file-name method user host remote-copy))))) |
| 3196 | (list (expand-file-name filename) | 3196 | |
| 3197 | (cadr result)))) | 3197 | ;; Result. |
| 3198 | (list (expand-file-name filename) | ||
| 3199 | (cadr result))))) | ||
| 3198 | 3200 | ||
| 3199 | (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix) | 3201 | (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix) |
| 3200 | "Like `load' for Tramp files." | 3202 | "Like `load' for Tramp files." |