diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2019-11-04 17:34:31 +0100 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2019-11-04 17:34:31 +0100 |
commit | dd19cc3aa16ccc441a8a2bfcdeb3005a6eef2543 (patch) | |
tree | 42bd79ad2020a595244d981f0598b6e4595191bc /lisp | |
parent | a256e03bd944384efb3da05858264a5d3b72462d (diff) | |
download | emacs-dd19cc3aa16ccc441a8a2bfcdeb3005a6eef2543.tar.gz emacs-dd19cc3aa16ccc441a8a2bfcdeb3005a6eef2543.tar.bz2 emacs-dd19cc3aa16ccc441a8a2bfcdeb3005a6eef2543.zip |
Improve Tramp error handling
* lisp/net/tramp.el (tramp-set-syntax): Add missing argument.
(tramp-signal-hook-function): Make it more robust.
(tramp-handle-directory-files):
* lisp/net/tramp-adb.el
(tramp-adb-handle-directory-files-and-attributes)
(tramp-adb-handle-copy-file, tramp-adb-handle-rename-file):
* lisp/net/tramp-gvfs.el (tramp-gvfs-do-copy-or-rename-file):
* lisp/net/tramp-rclone.el (tramp-rclone-do-copy-or-rename-file)
(tramp-rclone-handle-directory-files):
* lisp/net/tramp-sh.el (tramp-sh-handle-directory-files-and-attributes)
(tramp-sh-handle-copy-directory, tramp-do-copy-or-rename-file):
* lisp/net/tramp-smb.el (tramp-smb-handle-copy-directory)
(tramp-smb-handle-copy-file, tramp-smb-handle-directory-files)
(tramp-smb-handle-rename-file):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-do-copy-or-rename-file):
Improve error handling.
* test/lisp/net/tramp-tests.el (tramp-test11-copy-file)
(tramp-test12-rename-file, tramp-test14-delete-directory)
(tramp-test15-copy-directory, tramp-test16-directory-files)
(tramp-test19-directory-files-and-attributes): Extend tests.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/net/tramp-adb.el | 12 | ||||
-rw-r--r-- | lisp/net/tramp-gvfs.el | 4 | ||||
-rw-r--r-- | lisp/net/tramp-rclone.el | 8 | ||||
-rw-r--r-- | lisp/net/tramp-sh.el | 11 | ||||
-rw-r--r-- | lisp/net/tramp-smb.el | 19 | ||||
-rw-r--r-- | lisp/net/tramp-sudoedit.el | 4 | ||||
-rw-r--r-- | lisp/net/tramp.el | 15 |
7 files changed, 70 insertions, 3 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index e1706bebe6e..e3098190e2b 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -383,6 +383,10 @@ ARGUMENTS to pass to the OPERATION." (defun tramp-adb-handle-directory-files-and-attributes (directory &optional full match nosort id-format) "Like `directory-files-and-attributes' for Tramp files." + (unless (file-exists-p directory) + (tramp-error + (tramp-dissect-file-name directory) tramp-file-missing + "No such file or directory" directory)) (when (file-directory-p directory) (with-parsed-tramp-file-name (expand-file-name directory) nil (copy-tree @@ -706,6 +710,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (let ((t1 (tramp-tramp-file-p filename)) (t2 (tramp-tramp-file-p newname))) (with-parsed-tramp-file-name (if t1 filename newname) nil + (unless (file-exists-p filename) + (tramp-error + v tramp-file-missing + "Copying file" "No such file or directory" filename)) (when (and (not ok-if-already-exists) (file-exists-p newname)) (tramp-error v 'file-already-exists newname)) (when (and (file-directory-p newname) @@ -784,6 +792,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (let ((t1 (tramp-tramp-file-p filename)) (t2 (tramp-tramp-file-p newname))) (with-parsed-tramp-file-name (if t1 filename newname) nil + (unless (file-exists-p filename) + (tramp-error + v tramp-file-missing + "Renaming file" "No such file or directory" filename)) (when (and (not ok-if-already-exists) (file-exists-p newname)) (tramp-error v 'file-already-exists newname)) (when (and (file-directory-p newname) diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index c08c7194cc7..6f5cade4c63 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -765,6 +765,10 @@ file names." (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) (with-parsed-tramp-file-name (if t1 filename newname) nil + (unless (file-exists-p filename) + (tramp-error + v tramp-file-missing + "%s file" msg-operation "No such file or directory" filename)) (when (and (not ok-if-already-exists) (file-exists-p newname)) (tramp-error v 'file-already-exists newname)) (when (and (file-directory-p newname) diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el index 1f0c7eadbc5..2b3799ef008 100644 --- a/lisp/net/tramp-rclone.el +++ b/lisp/net/tramp-rclone.el @@ -213,6 +213,10 @@ file names." (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) (with-parsed-tramp-file-name (if t1 filename newname) nil + (unless (file-exists-p filename) + (tramp-error + v tramp-file-missing + "%s file" msg-operation "No such file or directory" filename)) (when (and (not ok-if-already-exists) (file-exists-p newname)) (tramp-error v 'file-already-exists newname)) (when (and (file-directory-p newname) @@ -298,6 +302,10 @@ file names." (defun tramp-rclone-handle-directory-files (directory &optional full match nosort) "Like `directory-files' for Tramp files." + (unless (file-exists-p directory) + (tramp-error + (tramp-dissect-file-name directory) tramp-file-missing + "No such file or directory" directory)) (when (file-directory-p directory) (setq directory (file-name-as-directory (expand-file-name directory))) (with-parsed-tramp-file-name directory nil diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 3c80c583099..be531ed3192 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -1713,6 +1713,10 @@ of." (directory &optional full match nosort id-format) "Like `directory-files-and-attributes' for Tramp files." (unless id-format (setq id-format 'integer)) + (unless (file-exists-p directory) + (tramp-error + (tramp-dissect-file-name directory) tramp-file-missing + "No such file or directory" directory)) (when (file-directory-p directory) (setq directory (expand-file-name directory)) (let* ((temp @@ -1923,6 +1927,10 @@ tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'" (let ((t1 (tramp-tramp-file-p dirname)) (t2 (tramp-tramp-file-p newname))) (with-parsed-tramp-file-name (if t1 dirname newname) nil + (unless (file-exists-p dirname) + (tramp-error + v tramp-file-missing + "Copying directory" "No such file or directory" dirname)) (if (and (not copy-contents) (tramp-get-method-parameter v 'tramp-copy-recursive) ;; When DIRNAME and NEWNAME are remote, they must have @@ -2011,6 +2019,9 @@ file names." (apply #'file-extended-attributes (list filename))))) (with-parsed-tramp-file-name (if t1 filename newname) nil + (unless (file-exists-p filename) + (tramp-error + v tramp-file-missing "No such file or directory" filename)) (when (and (not ok-if-already-exists) (file-exists-p newname)) (tramp-error v 'file-already-exists newname)) (when (and (file-directory-p newname) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 5e52b26e7c6..f87d4becfe0 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -415,6 +415,10 @@ pass to the OPERATION." (with-parsed-tramp-file-name (if t1 dirname newname) nil (with-tramp-progress-reporter v 0 (format "Copying %s to %s" dirname newname) + (unless (file-exists-p dirname) + (tramp-error + v tramp-file-missing + "Copying directory" "No such file or directory" dirname)) (when (and (file-directory-p newname) (not (tramp-compat-directory-name-p newname))) (tramp-error v 'file-already-exists newname)) @@ -570,6 +574,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (if (file-directory-p filename) (copy-directory filename newname keep-date 'parents 'copy-contents) + (unless (file-exists-p filename) + (tramp-error + (tramp-dissect-file-name + (if (tramp-tramp-file-p filename) filename newname)) + tramp-file-missing + "Copying file" "No such file or directory" filename)) + (let ((tmpfile (file-local-copy filename))) (if tmpfile ;; Remote filename. @@ -669,6 +680,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (defun tramp-smb-handle-directory-files (directory &optional full match nosort) "Like `directory-files' for Tramp files." + (unless (file-exists-p directory) + (tramp-error + (tramp-dissect-file-name directory) tramp-file-missing + "No such file or directory" directory)) (let ((result (mapcar #'directory-file-name (file-name-all-completions "" directory)))) ;; Discriminate with regexp. @@ -1333,6 +1348,10 @@ component is used as the target of the symlink." (with-parsed-tramp-file-name (if (tramp-tramp-file-p filename) filename newname) nil + (unless (file-exists-p filename) + (tramp-error + v tramp-file-missing + "Renaming file" "No such file or directory" filename)) (when (and (not ok-if-already-exists) (file-exists-p newname)) (tramp-error v 'file-already-exists newname)) (when (and (file-directory-p newname) diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index bfc9b3bdc3a..2d9d7ff7892 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el @@ -241,6 +241,10 @@ absolute file names." (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) (with-parsed-tramp-file-name (if t1 filename newname) nil + (unless (file-exists-p filename) + (tramp-error + v tramp-file-missing + "%s file" msg-operation "No such file or directory" filename)) (when (and (not ok-if-already-exists) (file-exists-p newname)) (tramp-error v 'file-already-exists newname)) (when (and (file-directory-p newname) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 21b6f0070f7..88ff36d98ea 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -719,7 +719,7 @@ Used in user option `tramp-syntax'. There are further variables to be set, depending on VALUE." ;; Check allowed values. (unless (memq value (tramp-syntax-values)) - (tramp-user-error "Wrong `tramp-syntax' %s" value)) + (tramp-user-error nil "Wrong `tramp-syntax' %s" value)) ;; Cleanup existing buffers. (unless (eq (symbol-value symbol) value) (tramp-cleanup-all-buffers)) @@ -1889,8 +1889,13 @@ the resulting error message." ;; This function provides traces in case of errors not triggered by ;; Tramp functions. (defun tramp-signal-hook-function (error-symbol data) - "Funtion to be called via `signal-hook-function'." - (tramp-error (car tramp-current-connection) error-symbol "%s" data)) + "Function to be called via `signal-hook-function'." + ;; `custom-initialize-*' functions provoke `void-variable' errors. + ;; We don't want to see them in the backtrace. + (unless (eq error-symbol 'void-variable) + (tramp-error + (car tramp-current-connection) error-symbol + "%s" (mapconcat (lambda (x) (format "%s" x)) data " ")))) (defmacro with-parsed-tramp-file-name (filename var &rest body) "Parse a Tramp filename and make components available in the body. @@ -3025,6 +3030,10 @@ User is always nil." (defun tramp-handle-directory-files (directory &optional full match nosort) "Like `directory-files' for Tramp files." + (unless (file-exists-p directory) + (tramp-error + (tramp-dissect-file-name directory) tramp-file-missing + "No such file or directory" directory)) (when (file-directory-p directory) (setq directory (file-name-as-directory (expand-file-name directory))) (let ((temp (nreverse (file-name-all-completions "" directory))) |