emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master f5a1315: Fix error in tramp-sh-handle-insert-directory


From: Michael Albinus
Subject: master f5a1315: Fix error in tramp-sh-handle-insert-directory
Date: Mon, 4 Jan 2021 10:32:41 -0500 (EST)

branch: master
commit f5a1315f1ea035f30d1161e4af200acafdfebe01
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    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.
---
 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 865ea4e..b43b448 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 896b997..819d69b 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))))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]