[Top][All Lists]

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

tramp (2.2.8-pre); tramp breaks dired-insert-subdir

From: nb
Subject: tramp (2.2.8-pre); tramp breaks dired-insert-subdir
Date: Mon, 07 Oct 2013 19:29:52 +1300

tramp-sh-handle-insert-directory assumes it only ever appends to the
buffer. As a result it violates the postcondition of insert-directory,
upon which (at least) dired-insert-subdir depends.

Test case:

1. Open a dired buffer over e.g. ssh. 
2. dired-insert-subdir a directory.
3. (Examine the markers in dired-subdir-alist.)
4. dired-insert-subdir a directory that's sorted before step 2's.
5. (Examine dired-subdir-alist again, note the markers are wrong.)

Fix this by recording the position of the end of the inserted directory
text, and using that instead of (point-max).

-- >8 --
Subject: [PATCH] Fix postcondition violation in 

`insert-directory' must leave point at the end of the inserted text.
Ensure this is the case.

 lisp/net/tramp-sh.el | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 4bc836b..2d20fef 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -2544,7 +2544,7 @@ This is like `dired-recursive-delete-directory' for Tramp 
                     'file-name-nondirectory (list localname)))))))
-      (let ((beg (point)))
+      (let ((beg (point)) eod)
        ;; We cannot use `insert-buffer-substring' because the Tramp
        ;; buffer changes its contents before insertion due to calling
        ;; `expand-file' and alike.
@@ -2573,22 +2573,25 @@ This is like `dired-recursive-delete-directory' for 
Tramp files."
          (forward-line 1)
          (delete-region (match-beginning 0) (point)))
+        ;; Record end of directory.
+        (setq eod (point-marker))
        ;; Some busyboxes are reluctant to discard colors.
        (unless (string-match "color" (tramp-get-connection-property v "ls" ""))
          (goto-char beg)
-         (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
+         (while (re-search-forward tramp-color-escape-sequence-regexp eod t)
            (replace-match "")))
        ;; Decode the output, it could be multibyte.
-        beg (point-max)
+        beg eod
         (or file-name-coding-system
             (and (boundp 'default-file-name-coding-system)
                  (symbol-value 'default-file-name-coding-system))))
        ;; The inserted file could be from somewhere else.
        (when (and (not wildcard) (not full-directory-p))
-         (goto-char (point-max))
+         (goto-char eod)
          (when (file-symlink-p filename)
            (goto-char (search-backward "->" beg 'noerror)))
@@ -2598,7 +2601,7 @@ This is like `dired-recursive-delete-directory' for Tramp 
           beg 'noerror)
          (replace-match (file-relative-name filename) t))
-       (goto-char (point-max))))))
+       (goto-char eod)))))
 ;; Canonicalization of file names.

reply via email to

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