aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2021-01-04 16:32:32 +0100
committerMichael Albinus2021-01-04 16:32:32 +0100
commitf5a1315f1ea035f30d1161e4af200acafdfebe01 (patch)
treed56494af6520cd410894e4e35a0e321a2609e0cb
parent56556b5f4d73d9c3683fa7573e6bd89f2ef37902 (diff)
downloademacs-f5a1315f1ea035f30d1161e4af200acafdfebe01.tar.gz
emacs-f5a1315f1ea035f30d1161e4af200acafdfebe01.zip
Fix error in tramp-sh-handle-insert-directory
* lisp/net/tramp-sh.el (tramp-sh-handle-insert-directory): Let buffer be unibyte when applying numbers returned with the ls --dired option. Reported by Justus Piater <Justus-dev@Piater.name>. * test/lisp/net/tramp-tests.el (tramp--test-check-files): Extend test.
-rw-r--r--lisp/net/tramp-sh.el9
-rw-r--r--test/lisp/net/tramp-tests.el16
2 files changed, 22 insertions, 3 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 865ea4e92a4..b43b4485fec 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -2672,7 +2672,8 @@ The method used must be an out-of-band method."
2672 (tramp-get-remote-null-device v)))) 2672 (tramp-get-remote-null-device v))))
2673 2673
2674 (save-restriction 2674 (save-restriction
2675 (let ((beg (point))) 2675 (let ((beg (point))
2676 (emc enable-multibyte-characters))
2676 (narrow-to-region (point) (point)) 2677 (narrow-to-region (point) (point))
2677 ;; We cannot use `insert-buffer-substring' because the Tramp 2678 ;; We cannot use `insert-buffer-substring' because the Tramp
2678 ;; buffer changes its contents before insertion due to calling 2679 ;; buffer changes its contents before insertion due to calling
@@ -2681,7 +2682,9 @@ The method used must be an out-of-band method."
2681 (with-current-buffer (tramp-get-buffer v) 2682 (with-current-buffer (tramp-get-buffer v)
2682 (buffer-string))) 2683 (buffer-string)))
2683 2684
2684 ;; Check for "--dired" output. 2685 ;; Check for "--dired" output. We must enable unibyte
2686 ;; strings, because the "--dired" output counts in bytes.
2687 (set-buffer-multibyte nil)
2685 (forward-line -2) 2688 (forward-line -2)
2686 (when (looking-at-p "//SUBDIRED//") 2689 (when (looking-at-p "//SUBDIRED//")
2687 (forward-line -1)) 2690 (forward-line -1))
@@ -2701,6 +2704,8 @@ The method used must be an out-of-band method."
2701 (while (looking-at "//") 2704 (while (looking-at "//")
2702 (forward-line 1) 2705 (forward-line 1)
2703 (delete-region (match-beginning 0) (point))) 2706 (delete-region (match-beginning 0) (point)))
2707 ;; Reset multibyte if needed.
2708 (set-buffer-multibyte emc)
2704 2709
2705 ;; Some busyboxes are reluctant to discard colors. 2710 ;; Some busyboxes are reluctant to discard colors.
2706 (unless 2711 (unless
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 896b9978e7c..819d69b600e 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -5787,7 +5787,8 @@ This requires restrictions of file name syntax."
5787 (tmp-name2 (tramp--test-make-temp-name 'local quoted)) 5787 (tmp-name2 (tramp--test-make-temp-name 'local quoted))
5788 (files (delq nil files)) 5788 (files (delq nil files))
5789 (process-environment process-environment) 5789 (process-environment process-environment)
5790 (sorted-files (sort (copy-sequence files) #'string-lessp))) 5790 (sorted-files (sort (copy-sequence files) #'string-lessp))
5791 buffer)
5791 (unwind-protect 5792 (unwind-protect
5792 (progn 5793 (progn
5793 (make-directory tmp-name1) 5794 (make-directory tmp-name1)
@@ -5849,6 +5850,18 @@ This requires restrictions of file name syntax."
5849 tmp-name2 nil directory-files-no-dot-files-regexp)) 5850 tmp-name2 nil directory-files-no-dot-files-regexp))
5850 sorted-files)) 5851 sorted-files))
5851 5852
5853 ;; Check, that `insert-directory' works properly.
5854 (with-current-buffer
5855 (setq buffer (dired-noselect tmp-name1 "--dired -al"))
5856 (goto-char (point-min))
5857 (while (not (eobp))
5858 (when-let ((name (dired-get-filename 'localp 'no-error)))
5859 (unless
5860 (string-match-p name directory-files-no-dot-files-regexp)
5861 (should (member name files))))
5862 (forward-line 1)))
5863 (kill-buffer buffer)
5864
5852 ;; `substitute-in-file-name' could return different 5865 ;; `substitute-in-file-name' could return different
5853 ;; values. For `adb', there could be strange file 5866 ;; values. For `adb', there could be strange file
5854 ;; permissions preventing overwriting a file. We don't 5867 ;; permissions preventing overwriting a file. We don't
@@ -5944,6 +5957,7 @@ This requires restrictions of file name syntax."
5944 (regexp-quote (getenv envvar)))))))))) 5957 (regexp-quote (getenv envvar))))))))))
5945 5958
5946 ;; Cleanup. 5959 ;; Cleanup.
5960 (ignore-errors (kill-buffer buffer))
5947 (ignore-errors (delete-directory tmp-name1 'recursive)) 5961 (ignore-errors (delete-directory tmp-name1 'recursive))
5948 (ignore-errors (delete-directory tmp-name2 'recursive)))))) 5962 (ignore-errors (delete-directory tmp-name2 'recursive))))))
5949 5963