diff options
| author | Michael Albinus | 2019-11-06 16:49:35 +0100 |
|---|---|---|
| committer | Michael Albinus | 2019-11-06 16:49:35 +0100 |
| commit | da2df1c1b5b5a7373f361875b43dd003a221e2e0 (patch) | |
| tree | 10be03ac989db4fc075422d9648b5f816b3bc898 | |
| parent | d30f5e7eeecd5425e236542189a1d683c00e7ed7 (diff) | |
| download | emacs-da2df1c1b5b5a7373f361875b43dd003a221e2e0.tar.gz emacs-da2df1c1b5b5a7373f361875b43dd003a221e2e0.zip | |
More error checks in Tramp's make-directory
* lisp/net/tramp-adb.el (tramp-adb-handle-make-directory):
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-make-directory):
* lisp/net/tramp-sh.el (tramp-sh-handle-make-directory):
* lisp/net/tramp-smb.el (tramp-smb-handle-make-directory):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-make-directory):
Signal `file-already-exists' if DIR exists.
* test/lisp/net/tramp-tests.el (tramp-test04-substitute-in-file-name):
Fix thinko.
(tramp-test13-make-directory, tramp-test14-delete-directory)
(tramp-test15-copy-directory): Extend tests.
| -rw-r--r-- | lisp/net/tramp-adb.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-gvfs.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-smb.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-sudoedit.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 4 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 23 |
7 files changed, 29 insertions, 8 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index a4f5760f72e..cfbda0824e7 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el | |||
| @@ -514,6 +514,8 @@ Emacs dired can't find files." | |||
| 514 | "Like `make-directory' for Tramp files." | 514 | "Like `make-directory' for Tramp files." |
| 515 | (setq dir (expand-file-name dir)) | 515 | (setq dir (expand-file-name dir)) |
| 516 | (with-parsed-tramp-file-name dir nil | 516 | (with-parsed-tramp-file-name dir nil |
| 517 | (when (and (null parents) (file-exists-p dir)) | ||
| 518 | (tramp-error v 'file-already-exists "Directory already exists %s" dir)) | ||
| 517 | (when parents | 519 | (when parents |
| 518 | (let ((par (expand-file-name ".." dir))) | 520 | (let ((par (expand-file-name ".." dir))) |
| 519 | (unless (file-directory-p par) | 521 | (unless (file-directory-p par) |
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index dbda24b9ac1..f13564c544e 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el | |||
| @@ -1310,6 +1310,8 @@ file-notify events." | |||
| 1310 | "Like `make-directory' for Tramp files." | 1310 | "Like `make-directory' for Tramp files." |
| 1311 | (setq dir (directory-file-name (expand-file-name dir))) | 1311 | (setq dir (directory-file-name (expand-file-name dir))) |
| 1312 | (with-parsed-tramp-file-name dir nil | 1312 | (with-parsed-tramp-file-name dir nil |
| 1313 | (when (and (null parents) (file-exists-p dir)) | ||
| 1314 | (tramp-error v 'file-already-exists "Directory already exists %s" dir)) | ||
| 1313 | (tramp-flush-directory-properties v localname) | 1315 | (tramp-flush-directory-properties v localname) |
| 1314 | (save-match-data | 1316 | (save-match-data |
| 1315 | (let ((ldir (file-name-directory dir))) | 1317 | (let ((ldir (file-name-directory dir))) |
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index be531ed3192..76bb10a277f 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -2513,6 +2513,8 @@ The method used must be an out-of-band method." | |||
| 2513 | "Like `make-directory' for Tramp files." | 2513 | "Like `make-directory' for Tramp files." |
| 2514 | (setq dir (expand-file-name dir)) | 2514 | (setq dir (expand-file-name dir)) |
| 2515 | (with-parsed-tramp-file-name dir nil | 2515 | (with-parsed-tramp-file-name dir nil |
| 2516 | (when (and (null parents) (file-exists-p dir)) | ||
| 2517 | (tramp-error v 'file-already-exists "Directory already exists %s" dir)) | ||
| 2516 | ;; When PARENTS is non-nil, DIR could be a chain of non-existent | 2518 | ;; When PARENTS is non-nil, DIR could be a chain of non-existent |
| 2517 | ;; directories a/b/c/... Instead of checking, we simply flush the | 2519 | ;; directories a/b/c/... Instead of checking, we simply flush the |
| 2518 | ;; whole cache. | 2520 | ;; whole cache. |
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index f87d4becfe0..95cdb4cbffe 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el | |||
| @@ -1139,6 +1139,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 1139 | (unless (file-name-absolute-p dir) | 1139 | (unless (file-name-absolute-p dir) |
| 1140 | (setq dir (expand-file-name dir default-directory))) | 1140 | (setq dir (expand-file-name dir default-directory))) |
| 1141 | (with-parsed-tramp-file-name dir nil | 1141 | (with-parsed-tramp-file-name dir nil |
| 1142 | (when (and (null parents) (file-exists-p dir)) | ||
| 1143 | (tramp-error v 'file-already-exists "Directory already exists %s" dir)) | ||
| 1142 | (let* ((ldir (file-name-directory dir))) | 1144 | (let* ((ldir (file-name-directory dir))) |
| 1143 | ;; Make missing directory parts. | 1145 | ;; Make missing directory parts. |
| 1144 | (when (and parents | 1146 | (when (and parents |
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index e7a892c7465..43ac6ff66b3 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el | |||
| @@ -587,6 +587,8 @@ the result will be a local, non-Tramp, file name." | |||
| 587 | "Like `make-directory' for Tramp files." | 587 | "Like `make-directory' for Tramp files." |
| 588 | (setq dir (expand-file-name dir)) | 588 | (setq dir (expand-file-name dir)) |
| 589 | (with-parsed-tramp-file-name dir nil | 589 | (with-parsed-tramp-file-name dir nil |
| 590 | (when (and (null parents) (file-exists-p dir)) | ||
| 591 | (tramp-error v 'file-already-exists "Directory already exists %s" dir)) | ||
| 590 | ;; When PARENTS is non-nil, DIR could be a chain of non-existent | 592 | ;; When PARENTS is non-nil, DIR could be a chain of non-existent |
| 591 | ;; directories a/b/c/... Instead of checking, we simply flush the | 593 | ;; directories a/b/c/... Instead of checking, we simply flush the |
| 592 | ;; whole cache. | 594 | ;; whole cache. |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index acb5a93687c..09d125945a1 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -3019,8 +3019,8 @@ User is always nil." | |||
| 3019 | (defun tramp-handle-copy-directory | 3019 | (defun tramp-handle-copy-directory |
| 3020 | (directory newname &optional keep-date parents copy-contents) | 3020 | (directory newname &optional keep-date parents copy-contents) |
| 3021 | "Like `copy-directory' for Tramp files." | 3021 | "Like `copy-directory' for Tramp files." |
| 3022 | ;; `directory-files' creates `newname' before running this check. | 3022 | ;; `copy-directory' creates NEWNAME before running this check. So |
| 3023 | ;; So we do it ourselves. | 3023 | ;; we do it ourselves. |
| 3024 | (unless (file-exists-p directory) | 3024 | (unless (file-exists-p directory) |
| 3025 | (tramp-error | 3025 | (tramp-error |
| 3026 | (tramp-dissect-file-name directory) tramp-file-missing | 3026 | (tramp-dissect-file-name directory) tramp-file-missing |
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index ec9cda0bbdd..9b73f7ca28e 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -1958,7 +1958,7 @@ properly. BODY shall not contain a timeout." | |||
| 1958 | 1958 | ||
| 1959 | ;; Forwhatever reasons, the following tests let Emacs crash for | 1959 | ;; Forwhatever reasons, the following tests let Emacs crash for |
| 1960 | ;; Emacs 24 and Emacs 25, occasionally. No idea what's up. | 1960 | ;; Emacs 24 and Emacs 25, occasionally. No idea what's up. |
| 1961 | (when (or (tramp--test-emacs26-p) (tramp--test-emacs27-p)) | 1961 | (when (tramp--test-emacs26-p) |
| 1962 | (should | 1962 | (should |
| 1963 | (string-equal (substitute-in-file-name "/method:host://~foo") "/~foo")) | 1963 | (string-equal (substitute-in-file-name "/method:host://~foo") "/~foo")) |
| 1964 | (should | 1964 | (should |
| @@ -2593,9 +2593,14 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." | |||
| 2593 | (unwind-protect | 2593 | (unwind-protect |
| 2594 | (progn | 2594 | (progn |
| 2595 | (make-directory tmp-name1) | 2595 | (make-directory tmp-name1) |
| 2596 | (should-error | ||
| 2597 | (make-directory tmp-name1) | ||
| 2598 | :type 'file-already-exists) | ||
| 2596 | (should (file-directory-p tmp-name1)) | 2599 | (should (file-directory-p tmp-name1)) |
| 2597 | (should (file-accessible-directory-p tmp-name1)) | 2600 | (should (file-accessible-directory-p tmp-name1)) |
| 2598 | (should-error (make-directory tmp-name2) :type 'file-error) | 2601 | (should-error |
| 2602 | (make-directory tmp-name2) | ||
| 2603 | :type 'file-error) | ||
| 2599 | (make-directory tmp-name2 'parents) | 2604 | (make-directory tmp-name2 'parents) |
| 2600 | (should (file-directory-p tmp-name2)) | 2605 | (should (file-directory-p tmp-name2)) |
| 2601 | (should (file-accessible-directory-p tmp-name2)) | 2606 | (should (file-accessible-directory-p tmp-name2)) |
| @@ -2627,7 +2632,9 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." | |||
| 2627 | (should (file-directory-p tmp-name2)) | 2632 | (should (file-directory-p tmp-name2)) |
| 2628 | (write-region "foo" nil (expand-file-name "bla" tmp-name2)) | 2633 | (write-region "foo" nil (expand-file-name "bla" tmp-name2)) |
| 2629 | (should (file-exists-p (expand-file-name "bla" tmp-name2))) | 2634 | (should (file-exists-p (expand-file-name "bla" tmp-name2))) |
| 2630 | (should-error (delete-directory tmp-name1) :type 'file-error) | 2635 | (should-error |
| 2636 | (delete-directory tmp-name1) | ||
| 2637 | :type 'file-error) | ||
| 2631 | (delete-directory tmp-name1 'recursive) | 2638 | (delete-directory tmp-name1 'recursive) |
| 2632 | (should-not (file-directory-p tmp-name1))))) | 2639 | (should-not (file-directory-p tmp-name1))))) |
| 2633 | 2640 | ||
| @@ -2663,7 +2670,7 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." | |||
| 2663 | (when (tramp--test-emacs26-p) | 2670 | (when (tramp--test-emacs26-p) |
| 2664 | (should-error | 2671 | (should-error |
| 2665 | (copy-directory tmp-name1 tmp-name2) | 2672 | (copy-directory tmp-name1 tmp-name2) |
| 2666 | :type 'file-error)) | 2673 | :type 'file-already-exists)) |
| 2667 | (copy-directory tmp-name1 (file-name-as-directory tmp-name2)) | 2674 | (copy-directory tmp-name1 (file-name-as-directory tmp-name2)) |
| 2668 | (should (file-directory-p tmp-name3)) | 2675 | (should (file-directory-p tmp-name3)) |
| 2669 | (should (file-exists-p tmp-name6))) | 2676 | (should (file-exists-p tmp-name6))) |
| @@ -3523,7 +3530,9 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3523 | :type 'file-error) | 3530 | :type 'file-error) |
| 3524 | (make-symbolic-link tmp-name1 tmp-name2) | 3531 | (make-symbolic-link tmp-name1 tmp-name2) |
| 3525 | (should (file-symlink-p tmp-name2)) | 3532 | (should (file-symlink-p tmp-name2)) |
| 3526 | (should-error (file-truename tmp-name1) :type 'file-error)))) | 3533 | (should-error |
| 3534 | (file-truename tmp-name1) | ||
| 3535 | :type 'file-error)))) | ||
| 3527 | 3536 | ||
| 3528 | ;; Cleanup. | 3537 | ;; Cleanup. |
| 3529 | (ignore-errors | 3538 | (ignore-errors |
| @@ -4276,7 +4285,9 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4276 | (while (accept-process-output proc nil nil 0))) | 4285 | (while (accept-process-output proc nil nil 0))) |
| 4277 | (should-not (process-live-p proc)) | 4286 | (should-not (process-live-p proc)) |
| 4278 | ;; An interrupted process cannot be interrupted, again. | 4287 | ;; An interrupted process cannot be interrupted, again. |
| 4279 | (should-error (interrupt-process proc) :type 'error)) | 4288 | (should-error |
| 4289 | (interrupt-process proc) | ||
| 4290 | :type 'error)) | ||
| 4280 | 4291 | ||
| 4281 | ;; Cleanup. | 4292 | ;; Cleanup. |
| 4282 | (ignore-errors (delete-process proc))))) | 4293 | (ignore-errors (delete-process proc))))) |