]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix error in tramp-sh-handle-insert-directory
authorMichael Albinus <michael.albinus@gmx.de>
Mon, 4 Jan 2021 15:32:32 +0000 (16:32 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Mon, 4 Jan 2021 15:32:32 +0000 (16:32 +0100)
* 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
test/lisp/net/tramp-tests.el

index 865ea4e92a46f573de24b5581eec67386b31d8e5..b43b4485fece917f093063d1f67ab3fad16a37d4 100644 (file)
@@ -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
index 896b9978e7c7319555b79ed9d38f247887ce882a..819d69b600e469716e6e279df965f940f6bad61f 100644 (file)
@@ -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))))))