all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ivan Shmakov <ivan@siamics.net>
To: 19865@debbugs.gnu.org
Subject: bug#19865: tar-untar-buffer: should honor default-directory
Date: Sat, 14 Feb 2015 16:27:29 +0000	[thread overview]
Message-ID: <87bnkwbgr2.fsf@violet.siamics.net> (raw)
In-Reply-To: <87oaowbkgv.fsf@violet.siamics.net> (Ivan Shmakov's message of "Sat, 14 Feb 2015 15:07:12 +0000")

[-- Attachment #1: Type: text/plain, Size: 1537 bytes --]

>>>>> Ivan Shmakov <ivan@siamics.net> writes:

[…]

 > Avoiding switching buffers until around the actual write-region call
 > may still be a better alternative (as that should make mistakes of
 > this kind hardier to introduce), but results in a lengthier patch.
 > Any opinion on which way I should go there?

	Per my reading of the code, with-current-buffer is generally
	used in tar-mode.el around the smallest fragments possible.

	Please thus consider the revised patch MIMEd, which I’ve tried
	to make consistent with such an approach.

	Also to note is that the awareness of the general “data buffer
	default-directory” issue dates back to 2001 at the least
	(considering the excerpt below, for instance), so I don’t seem
	to understand how making tar-untar-buffer consistent with the
	rest of the tar-mode.el code could ever be harmful?

	TIA.

commit e8421604cdd386af0c32fb7cf698882ec6b74015
Author: Gerd Moellmann <gerd@gnu.org>
Date:   2001-08-07 13:36:14 +0000

    (tar-extract): Avoid generating a new buffer
    for each file visited.  From Markus Rost <rost@math.ohio-state.edu>.

$ git archive --format=tar  e8421604cdd3 -- tar-mode.el | tar -xO | nl -ba 
…
   749			;; Set the default-directory to the dir of the
   750			;; superior buffer. 
   751			(setq default-directory
   752			      (save-excursion
   753				(set-buffer tar-buffer)
   754				default-directory))
…
$ 

-- 
FSF associate member #7257  np. Meditation — David Modica 3013 B6A0 230E 334A

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/diff, Size: 2390 bytes --]

diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el
index 6c7f755..c6eef01 100644
--- a/lisp/tar-mode.el
+++ b/lisp/tar-mode.el
@@ -531,25 +531,28 @@ defun tar-untar-buffer ()
   "Extract all archive members in the tar-file into the current directory."
   (interactive)
   ;; FIXME: make it work even if we're not in tar-mode.
-  (let ((descriptors tar-parse-info))   ;Read the var in its buffer.
-    (with-current-buffer
-        (if (tar-data-swapped-p) tar-data-buffer (current-buffer))
-      (set-buffer-multibyte nil)          ;Hopefully, a no-op.
-      (dolist (descriptor descriptors)
-        (let* ((name (tar-header-name descriptor))
-               (dir (if (eq (tar-header-link-type descriptor) 5)
-                        name
-                      (file-name-directory name)))
-               (start (tar-header-data-start descriptor))
-               (end (+ start (tar-header-size descriptor))))
-          (unless (file-directory-p name)
-            (message "Extracting %s" name)
-            (if (and dir (not (file-exists-p dir)))
-                (make-directory dir t))
-            (unless (file-directory-p name)
-	      (let ((coding-system-for-write 'no-conversion))
-		(write-region start end name)))
-            (set-file-modes name (tar-header-mode descriptor))))))))
+  (let ((data-buf (if (tar-data-swapped-p) tar-data-buffer (current-buffer))))
+    (with-current-buffer data-buf
+      (set-buffer-multibyte nil))       ; Hopefully, a no-op.
+    (dolist (descriptor tar-parse-info)
+      (let* ((name (tar-header-name descriptor))
+	     (dir (if (eq (tar-header-link-type descriptor) 5)
+		      name
+		    (file-name-directory name)))
+	     (start (tar-header-data-start descriptor))
+	     (end (+ start (tar-header-size descriptor))))
+	(unless (file-directory-p name)
+	  (message "Extracting %s" name)
+	  (if (and dir (not (file-exists-p dir)))
+	      (make-directory dir t))
+	  (unless (file-directory-p name)
+	    (let ((coding-system-for-write 'no-conversion)
+		  ;; Note that default-directory may have a different
+		  ;; value in the data buffer.
+		  (name (expand-file-name name default-directory)))
+	      (with-current-buffer data-buf
+		(write-region start end name))))
+	  (set-file-modes name (tar-header-mode descriptor)))))))
 
 (defun tar-summarize-buffer ()
   "Parse the contents of the tar file in the current buffer."

  reply	other threads:[~2015-02-14 16:27 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-14 11:31 bug#19865: tar-untar-buffer: should honor default-directory Ivan Shmakov
2015-02-14 12:16 ` Eli Zaretskii
2015-02-14 12:27   ` Ivan Shmakov
2015-02-14 12:40     ` Eli Zaretskii
2015-02-14 12:47       ` Ivan Shmakov
2015-02-14 13:22         ` Eli Zaretskii
2015-02-14 13:34           ` Ivan Shmakov
2015-02-14 14:56             ` Eli Zaretskii
2015-02-14 15:16               ` Ivan Shmakov
2015-02-14 14:49 ` Stefan Monnier
2015-02-14 15:01   ` Eli Zaretskii
2015-02-16  1:43     ` Stefan Monnier
2015-02-16 15:43       ` Eli Zaretskii
2015-02-16 19:34         ` Stefan Monnier
2015-02-16 19:49           ` Eli Zaretskii
2015-02-16 23:40             ` Stefan Monnier
2015-02-17  3:37               ` Eli Zaretskii
2015-02-18  3:38                 ` Stefan Monnier
2015-02-17 17:03               ` Wolfgang Jenkner
2015-02-17 18:02                 ` Eli Zaretskii
2015-02-17  5:25             ` Ivan Shmakov
2015-02-17 15:46               ` Eli Zaretskii
2015-02-17 18:05                 ` Ivan Shmakov
2015-02-14 15:07   ` Ivan Shmakov
2015-02-14 16:27     ` Ivan Shmakov [this message]
2015-02-16  1:48       ` Stefan Monnier
2015-02-16  5:24         ` Ivan Shmakov
2015-02-16  7:45           ` Stefan Monnier
2015-02-16  8:55             ` Ivan Shmakov
2015-02-16 14:58               ` Stefan Monnier
2016-02-23 11:04           ` Lars Ingebrigtsen
2019-06-25 17:55             ` Lars Ingebrigtsen
2015-02-14 15:57 ` Ivan Shmakov
2015-02-14 16:56   ` Eli Zaretskii
2015-02-14 17:32     ` Ivan Shmakov
2015-02-14 17:44       ` Eli Zaretskii
2015-02-14 18:12         ` Ivan Shmakov
2015-02-14 18:37           ` Eli Zaretskii
2015-02-14 19:12             ` Ivan Shmakov
2015-02-14 19:28               ` Eli Zaretskii
2015-02-14 19:42                 ` Ivan Shmakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bnkwbgr2.fsf@violet.siamics.net \
    --to=ivan@siamics.net \
    --cc=19865@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.