diff options
| author | Michael Albinus | 2019-11-04 17:34:31 +0100 |
|---|---|---|
| committer | Michael Albinus | 2019-11-04 17:34:31 +0100 |
| commit | dd19cc3aa16ccc441a8a2bfcdeb3005a6eef2543 (patch) | |
| tree | 42bd79ad2020a595244d981f0598b6e4595191bc /lisp/net | |
| parent | a256e03bd944384efb3da05858264a5d3b72462d (diff) | |
| download | emacs-dd19cc3aa16ccc441a8a2bfcdeb3005a6eef2543.tar.gz 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/net')
| -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." | |||
| 383 | (defun tramp-adb-handle-directory-files-and-attributes | 383 | (defun tramp-adb-handle-directory-files-and-attributes |
| 384 | (directory &optional full match nosort id-format) | 384 | (directory &optional full match nosort id-format) |
| 385 | "Like `directory-files-and-attributes' for Tramp files." | 385 | "Like `directory-files-and-attributes' for Tramp files." |
| 386 | (unless (file-exists-p directory) | ||
| 387 | (tramp-error | ||
| 388 | (tramp-dissect-file-name directory) tramp-file-missing | ||
| 389 | "No such file or directory" directory)) | ||
| 386 | (when (file-directory-p directory) | 390 | (when (file-directory-p directory) |
| 387 | (with-parsed-tramp-file-name (expand-file-name directory) nil | 391 | (with-parsed-tramp-file-name (expand-file-name directory) nil |
| 388 | (copy-tree | 392 | (copy-tree |
| @@ -706,6 +710,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 706 | (let ((t1 (tramp-tramp-file-p filename)) | 710 | (let ((t1 (tramp-tramp-file-p filename)) |
| 707 | (t2 (tramp-tramp-file-p newname))) | 711 | (t2 (tramp-tramp-file-p newname))) |
| 708 | (with-parsed-tramp-file-name (if t1 filename newname) nil | 712 | (with-parsed-tramp-file-name (if t1 filename newname) nil |
| 713 | (unless (file-exists-p filename) | ||
| 714 | (tramp-error | ||
| 715 | v tramp-file-missing | ||
| 716 | "Copying file" "No such file or directory" filename)) | ||
| 709 | (when (and (not ok-if-already-exists) (file-exists-p newname)) | 717 | (when (and (not ok-if-already-exists) (file-exists-p newname)) |
| 710 | (tramp-error v 'file-already-exists newname)) | 718 | (tramp-error v 'file-already-exists newname)) |
| 711 | (when (and (file-directory-p newname) | 719 | (when (and (file-directory-p newname) |
| @@ -784,6 +792,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 784 | (let ((t1 (tramp-tramp-file-p filename)) | 792 | (let ((t1 (tramp-tramp-file-p filename)) |
| 785 | (t2 (tramp-tramp-file-p newname))) | 793 | (t2 (tramp-tramp-file-p newname))) |
| 786 | (with-parsed-tramp-file-name (if t1 filename newname) nil | 794 | (with-parsed-tramp-file-name (if t1 filename newname) nil |
| 795 | (unless (file-exists-p filename) | ||
| 796 | (tramp-error | ||
| 797 | v tramp-file-missing | ||
| 798 | "Renaming file" "No such file or directory" filename)) | ||
| 787 | (when (and (not ok-if-already-exists) (file-exists-p newname)) | 799 | (when (and (not ok-if-already-exists) (file-exists-p newname)) |
| 788 | (tramp-error v 'file-already-exists newname)) | 800 | (tramp-error v 'file-already-exists newname)) |
| 789 | (when (and (file-directory-p newname) | 801 | (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." | |||
| 765 | (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) | 765 | (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) |
| 766 | 766 | ||
| 767 | (with-parsed-tramp-file-name (if t1 filename newname) nil | 767 | (with-parsed-tramp-file-name (if t1 filename newname) nil |
| 768 | (unless (file-exists-p filename) | ||
| 769 | (tramp-error | ||
| 770 | v tramp-file-missing | ||
| 771 | "%s file" msg-operation "No such file or directory" filename)) | ||
| 768 | (when (and (not ok-if-already-exists) (file-exists-p newname)) | 772 | (when (and (not ok-if-already-exists) (file-exists-p newname)) |
| 769 | (tramp-error v 'file-already-exists newname)) | 773 | (tramp-error v 'file-already-exists newname)) |
| 770 | (when (and (file-directory-p newname) | 774 | (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." | |||
| 213 | (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) | 213 | (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) |
| 214 | 214 | ||
| 215 | (with-parsed-tramp-file-name (if t1 filename newname) nil | 215 | (with-parsed-tramp-file-name (if t1 filename newname) nil |
| 216 | (unless (file-exists-p filename) | ||
| 217 | (tramp-error | ||
| 218 | v tramp-file-missing | ||
| 219 | "%s file" msg-operation "No such file or directory" filename)) | ||
| 216 | (when (and (not ok-if-already-exists) (file-exists-p newname)) | 220 | (when (and (not ok-if-already-exists) (file-exists-p newname)) |
| 217 | (tramp-error v 'file-already-exists newname)) | 221 | (tramp-error v 'file-already-exists newname)) |
| 218 | (when (and (file-directory-p newname) | 222 | (when (and (file-directory-p newname) |
| @@ -298,6 +302,10 @@ file names." | |||
| 298 | (defun tramp-rclone-handle-directory-files | 302 | (defun tramp-rclone-handle-directory-files |
| 299 | (directory &optional full match nosort) | 303 | (directory &optional full match nosort) |
| 300 | "Like `directory-files' for Tramp files." | 304 | "Like `directory-files' for Tramp files." |
| 305 | (unless (file-exists-p directory) | ||
| 306 | (tramp-error | ||
| 307 | (tramp-dissect-file-name directory) tramp-file-missing | ||
| 308 | "No such file or directory" directory)) | ||
| 301 | (when (file-directory-p directory) | 309 | (when (file-directory-p directory) |
| 302 | (setq directory (file-name-as-directory (expand-file-name directory))) | 310 | (setq directory (file-name-as-directory (expand-file-name directory))) |
| 303 | (with-parsed-tramp-file-name directory nil | 311 | (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." | |||
| 1713 | (directory &optional full match nosort id-format) | 1713 | (directory &optional full match nosort id-format) |
| 1714 | "Like `directory-files-and-attributes' for Tramp files." | 1714 | "Like `directory-files-and-attributes' for Tramp files." |
| 1715 | (unless id-format (setq id-format 'integer)) | 1715 | (unless id-format (setq id-format 'integer)) |
| 1716 | (unless (file-exists-p directory) | ||
| 1717 | (tramp-error | ||
| 1718 | (tramp-dissect-file-name directory) tramp-file-missing | ||
| 1719 | "No such file or directory" directory)) | ||
| 1716 | (when (file-directory-p directory) | 1720 | (when (file-directory-p directory) |
| 1717 | (setq directory (expand-file-name directory)) | 1721 | (setq directory (expand-file-name directory)) |
| 1718 | (let* ((temp | 1722 | (let* ((temp |
| @@ -1923,6 +1927,10 @@ tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'" | |||
| 1923 | (let ((t1 (tramp-tramp-file-p dirname)) | 1927 | (let ((t1 (tramp-tramp-file-p dirname)) |
| 1924 | (t2 (tramp-tramp-file-p newname))) | 1928 | (t2 (tramp-tramp-file-p newname))) |
| 1925 | (with-parsed-tramp-file-name (if t1 dirname newname) nil | 1929 | (with-parsed-tramp-file-name (if t1 dirname newname) nil |
| 1930 | (unless (file-exists-p dirname) | ||
| 1931 | (tramp-error | ||
| 1932 | v tramp-file-missing | ||
| 1933 | "Copying directory" "No such file or directory" dirname)) | ||
| 1926 | (if (and (not copy-contents) | 1934 | (if (and (not copy-contents) |
| 1927 | (tramp-get-method-parameter v 'tramp-copy-recursive) | 1935 | (tramp-get-method-parameter v 'tramp-copy-recursive) |
| 1928 | ;; When DIRNAME and NEWNAME are remote, they must have | 1936 | ;; When DIRNAME and NEWNAME are remote, they must have |
| @@ -2011,6 +2019,9 @@ file names." | |||
| 2011 | (apply #'file-extended-attributes (list filename))))) | 2019 | (apply #'file-extended-attributes (list filename))))) |
| 2012 | 2020 | ||
| 2013 | (with-parsed-tramp-file-name (if t1 filename newname) nil | 2021 | (with-parsed-tramp-file-name (if t1 filename newname) nil |
| 2022 | (unless (file-exists-p filename) | ||
| 2023 | (tramp-error | ||
| 2024 | v tramp-file-missing "No such file or directory" filename)) | ||
| 2014 | (when (and (not ok-if-already-exists) (file-exists-p newname)) | 2025 | (when (and (not ok-if-already-exists) (file-exists-p newname)) |
| 2015 | (tramp-error v 'file-already-exists newname)) | 2026 | (tramp-error v 'file-already-exists newname)) |
| 2016 | (when (and (file-directory-p newname) | 2027 | (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." | |||
| 415 | (with-parsed-tramp-file-name (if t1 dirname newname) nil | 415 | (with-parsed-tramp-file-name (if t1 dirname newname) nil |
| 416 | (with-tramp-progress-reporter | 416 | (with-tramp-progress-reporter |
| 417 | v 0 (format "Copying %s to %s" dirname newname) | 417 | v 0 (format "Copying %s to %s" dirname newname) |
| 418 | (unless (file-exists-p dirname) | ||
| 419 | (tramp-error | ||
| 420 | v tramp-file-missing | ||
| 421 | "Copying directory" "No such file or directory" dirname)) | ||
| 418 | (when (and (file-directory-p newname) | 422 | (when (and (file-directory-p newname) |
| 419 | (not (tramp-compat-directory-name-p newname))) | 423 | (not (tramp-compat-directory-name-p newname))) |
| 420 | (tramp-error v 'file-already-exists newname)) | 424 | (tramp-error v 'file-already-exists newname)) |
| @@ -570,6 +574,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 570 | (if (file-directory-p filename) | 574 | (if (file-directory-p filename) |
| 571 | (copy-directory filename newname keep-date 'parents 'copy-contents) | 575 | (copy-directory filename newname keep-date 'parents 'copy-contents) |
| 572 | 576 | ||
| 577 | (unless (file-exists-p filename) | ||
| 578 | (tramp-error | ||
| 579 | (tramp-dissect-file-name | ||
| 580 | (if (tramp-tramp-file-p filename) filename newname)) | ||
| 581 | tramp-file-missing | ||
| 582 | "Copying file" "No such file or directory" filename)) | ||
| 583 | |||
| 573 | (let ((tmpfile (file-local-copy filename))) | 584 | (let ((tmpfile (file-local-copy filename))) |
| 574 | (if tmpfile | 585 | (if tmpfile |
| 575 | ;; Remote filename. | 586 | ;; Remote filename. |
| @@ -669,6 +680,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 669 | (defun tramp-smb-handle-directory-files | 680 | (defun tramp-smb-handle-directory-files |
| 670 | (directory &optional full match nosort) | 681 | (directory &optional full match nosort) |
| 671 | "Like `directory-files' for Tramp files." | 682 | "Like `directory-files' for Tramp files." |
| 683 | (unless (file-exists-p directory) | ||
| 684 | (tramp-error | ||
| 685 | (tramp-dissect-file-name directory) tramp-file-missing | ||
| 686 | "No such file or directory" directory)) | ||
| 672 | (let ((result (mapcar #'directory-file-name | 687 | (let ((result (mapcar #'directory-file-name |
| 673 | (file-name-all-completions "" directory)))) | 688 | (file-name-all-completions "" directory)))) |
| 674 | ;; Discriminate with regexp. | 689 | ;; Discriminate with regexp. |
| @@ -1333,6 +1348,10 @@ component is used as the target of the symlink." | |||
| 1333 | 1348 | ||
| 1334 | (with-parsed-tramp-file-name | 1349 | (with-parsed-tramp-file-name |
| 1335 | (if (tramp-tramp-file-p filename) filename newname) nil | 1350 | (if (tramp-tramp-file-p filename) filename newname) nil |
| 1351 | (unless (file-exists-p filename) | ||
| 1352 | (tramp-error | ||
| 1353 | v tramp-file-missing | ||
| 1354 | "Renaming file" "No such file or directory" filename)) | ||
| 1336 | (when (and (not ok-if-already-exists) (file-exists-p newname)) | 1355 | (when (and (not ok-if-already-exists) (file-exists-p newname)) |
| 1337 | (tramp-error v 'file-already-exists newname)) | 1356 | (tramp-error v 'file-already-exists newname)) |
| 1338 | (when (and (file-directory-p newname) | 1357 | (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." | |||
| 241 | (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) | 241 | (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) |
| 242 | 242 | ||
| 243 | (with-parsed-tramp-file-name (if t1 filename newname) nil | 243 | (with-parsed-tramp-file-name (if t1 filename newname) nil |
| 244 | (unless (file-exists-p filename) | ||
| 245 | (tramp-error | ||
| 246 | v tramp-file-missing | ||
| 247 | "%s file" msg-operation "No such file or directory" filename)) | ||
| 244 | (when (and (not ok-if-already-exists) (file-exists-p newname)) | 248 | (when (and (not ok-if-already-exists) (file-exists-p newname)) |
| 245 | (tramp-error v 'file-already-exists newname)) | 249 | (tramp-error v 'file-already-exists newname)) |
| 246 | (when (and (file-directory-p newname) | 250 | (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 | |||
| 719 | to be set, depending on VALUE." | 719 | to be set, depending on VALUE." |
| 720 | ;; Check allowed values. | 720 | ;; Check allowed values. |
| 721 | (unless (memq value (tramp-syntax-values)) | 721 | (unless (memq value (tramp-syntax-values)) |
| 722 | (tramp-user-error "Wrong `tramp-syntax' %s" value)) | 722 | (tramp-user-error nil "Wrong `tramp-syntax' %s" value)) |
| 723 | ;; Cleanup existing buffers. | 723 | ;; Cleanup existing buffers. |
| 724 | (unless (eq (symbol-value symbol) value) | 724 | (unless (eq (symbol-value symbol) value) |
| 725 | (tramp-cleanup-all-buffers)) | 725 | (tramp-cleanup-all-buffers)) |
| @@ -1889,8 +1889,13 @@ the resulting error message." | |||
| 1889 | ;; This function provides traces in case of errors not triggered by | 1889 | ;; This function provides traces in case of errors not triggered by |
| 1890 | ;; Tramp functions. | 1890 | ;; Tramp functions. |
| 1891 | (defun tramp-signal-hook-function (error-symbol data) | 1891 | (defun tramp-signal-hook-function (error-symbol data) |
| 1892 | "Funtion to be called via `signal-hook-function'." | 1892 | "Function to be called via `signal-hook-function'." |
| 1893 | (tramp-error (car tramp-current-connection) error-symbol "%s" data)) | 1893 | ;; `custom-initialize-*' functions provoke `void-variable' errors. |
| 1894 | ;; We don't want to see them in the backtrace. | ||
| 1895 | (unless (eq error-symbol 'void-variable) | ||
| 1896 | (tramp-error | ||
| 1897 | (car tramp-current-connection) error-symbol | ||
| 1898 | "%s" (mapconcat (lambda (x) (format "%s" x)) data " ")))) | ||
| 1894 | 1899 | ||
| 1895 | (defmacro with-parsed-tramp-file-name (filename var &rest body) | 1900 | (defmacro with-parsed-tramp-file-name (filename var &rest body) |
| 1896 | "Parse a Tramp filename and make components available in the body. | 1901 | "Parse a Tramp filename and make components available in the body. |
| @@ -3025,6 +3030,10 @@ User is always nil." | |||
| 3025 | 3030 | ||
| 3026 | (defun tramp-handle-directory-files (directory &optional full match nosort) | 3031 | (defun tramp-handle-directory-files (directory &optional full match nosort) |
| 3027 | "Like `directory-files' for Tramp files." | 3032 | "Like `directory-files' for Tramp files." |
| 3033 | (unless (file-exists-p directory) | ||
| 3034 | (tramp-error | ||
| 3035 | (tramp-dissect-file-name directory) tramp-file-missing | ||
| 3036 | "No such file or directory" directory)) | ||
| 3028 | (when (file-directory-p directory) | 3037 | (when (file-directory-p directory) |
| 3029 | (setq directory (file-name-as-directory (expand-file-name directory))) | 3038 | (setq directory (file-name-as-directory (expand-file-name directory))) |
| 3030 | (let ((temp (nreverse (file-name-all-completions "" directory))) | 3039 | (let ((temp (nreverse (file-name-all-completions "" directory))) |