From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Shmakov Newsgroups: gmane.emacs.bugs Subject: bug#19481: package.el: support .tar archives featuring a pax_global_header entry Date: Wed, 28 Jan 2015 20:54:33 +0000 Message-ID: <87386ulj7a.fsf@violet.siamics.net> References: <871tne5qsd.fsf@violet.siamics.net> <83bnmibbla.fsf@gnu.org> <87wq5649qu.fsf_-_@violet.siamics.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1422478517 30138 80.91.229.3 (28 Jan 2015 20:55:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Jan 2015 20:55:17 +0000 (UTC) To: 19481@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jan 28 21:55:16 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YGZdr-0005Qv-Vd for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 Jan 2015 21:55:16 +0100 Original-Received: from localhost ([::1]:55924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGZdr-000649-DB for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 Jan 2015 15:55:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGZdk-000614-Ki for bug-gnu-emacs@gnu.org; Wed, 28 Jan 2015 15:55:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGZdg-0001Yz-DQ for bug-gnu-emacs@gnu.org; Wed, 28 Jan 2015 15:55:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGZde-0001Vc-Qn for bug-gnu-emacs@gnu.org; Wed, 28 Jan 2015 15:55:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YGZde-00011W-3R for bug-gnu-emacs@gnu.org; Wed, 28 Jan 2015 15:55:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Jan 2015 20:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19481 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 19481-submit@debbugs.gnu.org id=B19481.14224784893910 (code B ref 19481); Wed, 28 Jan 2015 20:55:01 +0000 Original-Received: (at 19481) by debbugs.gnu.org; 28 Jan 2015 20:54:49 +0000 Original-Received: from localhost ([127.0.0.1]:56711 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YGZdQ-00010y-NU for submit@debbugs.gnu.org; Wed, 28 Jan 2015 15:54:49 -0500 Original-Received: from fely.am-1.org ([78.47.74.50]:41014) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YGZdN-00010l-Jn for 19481@debbugs.gnu.org; Wed, 28 Jan 2015 15:54:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=siamics.net; s=a2013295; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:Sender:References:Subject:To:From; bh=gCbDHr9e/6ifnRknLjHRPDv2hGAvSm0VK+J6lMNh0IE=; b=SKPqpDnZLwWWV/UB46Ja48roTwkKD0/byFIsemkbLDPofFo00sCybstosx4a2yxlkkt9XRXdDeSicMSNx2Qyr5mh6XLYXcVGMM5omoBEUVg9rzL2p8VqCPGAr5pEAmq8Wg1YR5MULg+VfveptDGvtO6k9lnRcjHyZ30kfGtgVLU=; Original-Received: from [2a02:2560:6d4:26ca::1:1d] (helo=violet.siamics.net) by fely.am-1.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YGZdJ-0004AE-Mw for 19481@debbugs.gnu.org; Wed, 28 Jan 2015 20:54:42 +0000 Original-Received: from localhost ([::1] helo=violet.siamics.net) by violet.siamics.net with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YGZdC-0005Cm-II for 19481@debbugs.gnu.org; Thu, 29 Jan 2015 03:54:34 +0700 Mail-Followup-To: 19481@debbugs.gnu.org In-Reply-To: <87wq5649qu.fsf_-_@violet.siamics.net> (Ivan Shmakov's message of "Thu, 01 Jan 2015 18:49:13 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:98846 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> Ivan Shmakov writes: >>>>> Eli Zaretskii writes: >>>>> From: Ivan Shmakov Date: Thu, 01 Jan 2015 17:55:46 +0000 [=E2=80=A6] >>> * lisp/tar-mode.el (tar-untar-buffer): Ignore archive entries with >>> link type being 55 (pax global extended header.) >> What about type 72? > Frankly, =E2=80=93 no idea; I don=E2=80=99t 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. [=E2=80=A6] --=20 FSF associate member #7257 http://boycottsystemd.org/ =E2=80=A6 3013 B6A0= 230E 334A --=-=-= Content-Type: text/diff Content-Disposition: inline --- 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)) --=-=-=--