From f5a1315f1ea035f30d1161e4af200acafdfebe01 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Mon, 4 Jan 2021 16:32:32 +0100 Subject: [PATCH] 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 . * test/lisp/net/tramp-tests.el (tramp--test-check-files): Extend test. --- lisp/net/tramp-sh.el | 9 +++++++-- test/lisp/net/tramp-tests.el | 16 +++++++++++++++- 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." (tramp-get-remote-null-device v)))) (save-restriction - (let ((beg (point))) + (let ((beg (point)) + (emc enable-multibyte-characters)) (narrow-to-region (point) (point)) ;; We cannot use `insert-buffer-substring' because the Tramp ;; buffer changes its contents before insertion due to calling @@ -2681,7 +2682,9 @@ The method used must be an out-of-band method." (with-current-buffer (tramp-get-buffer v) (buffer-string))) - ;; Check for "--dired" output. + ;; Check for "--dired" output. We must enable unibyte + ;; strings, because the "--dired" output counts in bytes. + (set-buffer-multibyte nil) (forward-line -2) (when (looking-at-p "//SUBDIRED//") (forward-line -1)) @@ -2701,6 +2704,8 @@ The method used must be an out-of-band method." (while (looking-at "//") (forward-line 1) (delete-region (match-beginning 0) (point))) + ;; Reset multibyte if needed. + (set-buffer-multibyte emc) ;; Some busyboxes are reluctant to discard colors. (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." (tmp-name2 (tramp--test-make-temp-name 'local quoted)) (files (delq nil files)) (process-environment process-environment) - (sorted-files (sort (copy-sequence files) #'string-lessp))) + (sorted-files (sort (copy-sequence files) #'string-lessp)) + buffer) (unwind-protect (progn (make-directory tmp-name1) @@ -5849,6 +5850,18 @@ This requires restrictions of file name syntax." tmp-name2 nil directory-files-no-dot-files-regexp)) sorted-files)) + ;; Check, that `insert-directory' works properly. + (with-current-buffer + (setq buffer (dired-noselect tmp-name1 "--dired -al")) + (goto-char (point-min)) + (while (not (eobp)) + (when-let ((name (dired-get-filename 'localp 'no-error))) + (unless + (string-match-p name directory-files-no-dot-files-regexp) + (should (member name files)))) + (forward-line 1))) + (kill-buffer buffer) + ;; `substitute-in-file-name' could return different ;; values. For `adb', there could be strange file ;; permissions preventing overwriting a file. We don't @@ -5944,6 +5957,7 @@ This requires restrictions of file name syntax." (regexp-quote (getenv envvar)))))))))) ;; Cleanup. + (ignore-errors (kill-buffer buffer)) (ignore-errors (delete-directory tmp-name1 'recursive)) (ignore-errors (delete-directory tmp-name2 'recursive)))))) -- 2.39.5