all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ivan Shmakov <ivan@siamics.net>
To: 19481@debbugs.gnu.org
Subject: bug#19481: package.el: support .tar archives featuring a pax_global_header entry
Date: Wed, 28 Jan 2015 20:54:33 +0000	[thread overview]
Message-ID: <87386ulj7a.fsf@violet.siamics.net> (raw)
In-Reply-To: <87wq5649qu.fsf_-_@violet.siamics.net> (Ivan Shmakov's message of "Thu, 01 Jan 2015 18:49:13 +0000")

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

>>>>> Ivan Shmakov <ivan@siamics.net> writes:
>>>>> Eli Zaretskii <eliz@gnu.org> writes:
>>>>> From: Ivan Shmakov  Date: Thu, 01 Jan 2015 17:55:46 +0000

[…]

 >>> * lisp/tar-mode.el (tar-untar-buffer): Ignore archive entries with
 >>> link type being 55 (pax global extended header.)

 >> What about type 72?

 > Frankly, – no idea; I don’t seem to recall seeing one so far.

 > In order not to place such checks all over the code, we may want
 > either a separate tar-header-service-p function for the
 > tar-untar-buffer callers to use to decide whether the file will be
 > extracted or not, /or/ an optional filter function argument to
 > tar-untar-buffer for the /caller/ to specify which files to filter
 > out.

	Please consider the revised patch MIMEd.

	* lisp/tar-mode.el (tar-header-extractable-p): New function.
	(tar-untar-buffer): Use it; or use the value of the new optional
	argument instead.

	* lisp/emacs-lisp/package.el (package-untar-buffer): Use
	tar-header-extractable-p.
	(package-tar-file-info): Consider the second file name in the
	archive if the first one has no directory component.

[…]

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A

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

--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -757,6 +757,8 @@ defun package-untar-buffer (dir)
     (dolist (tar-data tar-parse-info)
       (let ((name (expand-file-name (tar-header-name tar-data))))
 	(or (string-match regexp name)
+	    ;; Ignore non-extractable entries (e. g., pax_global_header.)
+	    (not (tar-header-extractable-p tar-data))
 	    ;; Tarballs created by some utilities don't list
 	    ;; directories with a trailing slash (Bug#13136).
 	    (and (string-equal dir name)
@@ -1291,4 +1293,3 @@ defun package-tar-file-info ()
   "Find package information for a tar file.
 The return result is a `package-desc'."
   (cl-assert (derived-mode-p 'tar-mode))
-  (let* ((dir-name (file-name-directory
e-                    (tar-header-name (car tar-parse-info))))
+  (let* ((dir-name
+	  ;; Take care of pax_global_header, if any.
+	  (or (file-name-directory (tar-header-name (car  tar-parse-info)))
+	      (file-name-directory (tar-header-name (cadr tar-parse-info)))))
          (desc-file (package--description-file dir-name))
          (tar-desc (tar-get-file-descriptor (concat dir-name desc-file))))
     (unless tar-desc
--- a/lisp/tar-mode.el
+++ b/lisp/tar-mode.el
@@ -331,6 +331,17 @@
            (tar-roundup-512 size)
          0))))
 
+(defun tar-header-extractable-p (descriptor)
+  "Return non-nil if DESCRIPTOR refers to a file we can extract.
+Currently tar-mode only supports extracting regular files and (to a
+limited extent) directories.
+
+If DESCRIPTOR is an integer, it is handled as a link type."
+  (let ((type (if (integerp descriptor)
+		  descriptor
+		(tar-header-link-type descriptor))))
+    (memq '(nil 0 5) type)))
+
 (defun tar-parse-octal-integer (string &optional start end)
   (if (null start) (setq start 0))
   (if (null end) (setq end (length string)))
@@ -531,9 +542,17 @@
 		(concat (if (= type 1) " ==> " " --> ") link-name)
 	      ""))))
 
-(defun tar-untar-buffer ()
-  "Extract all archive members in the tar-file into the current directory."
+(defun tar-untar-buffer (&optional filter)
+  "Extract all archive members in the tar-file into the current directory.
+
+Optional FILTER is a function called with the Tar header (descriptor)
+as its only argument for each of archive members in turn.  Any given
+member will only be extracted if the function returns non-nil.
+
+If FILTER is not given or nil, use `tar-header-extractable-p'."
   (interactive)
+  (unless filter
+    (setq filter 'tar-header-extractable-p))
   ;; 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
@@ -546,7 +565,8 @@ defun tar-untar-buffer ()
                       (file-name-directory name)))
                (start (tar-header-data-start descriptor))
                (end (+ start (tar-header-size descriptor))))
-          (unless (file-directory-p name)
+          (when (and (not (file-directory-p name))
+                     (funcall filter descriptor))
             (message "Extracting %s" name)
             (if (and dir (not (file-exists-p dir)))
                 (make-directory dir t))

  reply	other threads:[~2015-01-28 20:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-01 17:55 bug#19481: package.el: support .tar archives featuring a pax_global_header entry Ivan Shmakov
2015-01-01 18:27 ` Eli Zaretskii
2015-01-01 18:49   ` Ivan Shmakov
2015-01-28 20:54     ` Ivan Shmakov [this message]
2015-01-31  8:41       ` Eli Zaretskii
2015-01-31 11:05         ` Ivan Shmakov
2015-01-31 11:22           ` Eli Zaretskii
2015-02-07 20:10             ` bug#19481: new tar-header-extractable-p, to use in tar-untar-buffer Ivan Shmakov
2015-02-07 20:26               ` Eli Zaretskii
2016-02-23 11:30                 ` Lars Ingebrigtsen
2019-06-25 20:53           ` bug#19481: package.el: support .tar archives featuring a pax_global_header entry Lars Ingebrigtsen
2020-01-20 18:35             ` Stefan Monnier
2020-08-13  9:01               ` Lars Ingebrigtsen
2020-08-19 13:42                 ` Lars Ingebrigtsen
2015-01-01 18:38 ` Dmitry Gutov

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=87386ulj7a.fsf@violet.siamics.net \
    --to=ivan@siamics.net \
    --cc=19481@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.