GNU bug report logs - #19865
tar-untar-buffer: should honor default-directory

Previous Next

Package: emacs;

Reported by: Ivan Shmakov <ivan <at> siamics.net>

Date: Sat, 14 Feb 2015 11:32:01 UTC

Severity: minor

Tags: fixed, patch

Fixed in version 27.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #77 received at 19865 <at> debbugs.gnu.org (full text, mbox):

From: Ivan Shmakov <ivan <at> siamics.net>
To: 19865 <at> debbugs.gnu.org
Subject: Re: bug#19865: tar-untar-buffer: should honor default-directory 
Date: Mon, 16 Feb 2015 05:24:44 +0000
[Message part 1 (text/plain, inline)]
>>>>> Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:

[…]

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

 > I think it's better, indeed.

	I’ve revised the change to apply default-directory just once
	and use the result consistently throughout the function.

 > BTW, the (set-buffer-multibyte nil) should probably just be remove
 > (or replaced by a cl-assert)

	Done.

Fix default-directory handling in tar-untar-buffer.

* lisp/tar-mode.el (tar-untar-buffer): Fixed: use the value of
default-directory local to the tar-mode buffer (was:
tar-data-buffer); clean-up.
    
Fixes: debbugs:19865

PS.  Should the pending objections be resolved by sometime around
	18:00 UTC today, I’d happily push the change to ‘master’.

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A
[Message part 2 (text/diff, inline)]
--- a/lisp/tar-mode.el
+++ b/lisp/tar-mode.el
@@ -533,27 +533,32 @@
 
 (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 ((data-buf (if (tar-data-swapped-p) tar-data-buffer
+                    (current-buffer))))
+    (with-current-buffer data-buf
+      (cl-assert (not enable-multibyte-characters)))
+    (dolist (descriptor tar-parse-info)
+      (let* ((orig (tar-header-name descriptor))
+	     ;; Note that default-directory may have different values
+	     ;; in the tar-mode and data buffers, so we stick to the
+	     ;; absolute file name from now on.
+	     (name (expand-file-name orig))
+	     (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" orig)
+	  (if (and dir (not (file-exists-p dir)))
+	      (make-directory dir t))
+	  (unless (file-directory-p name)
+	    (with-current-buffer data-buf
 	      (let ((coding-system-for-write 'no-conversion))
-		(write-region start end name)))
-            (set-file-modes name (tar-header-mode descriptor))))))))
+		(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."

This bug report was last modified 5 years and 331 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.