From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58367: `package-install-file' rejects some .tar files (tentative patch) Date: Sat, 08 Oct 2022 12:25:33 -0400 Message-ID: References: <263dae3ce307236c2694a2bc0baa3f63@unbit.co.uk> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25934"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 58367@debbugs.gnu.org To: Richard Hopkins Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 08 18:26:12 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ohCeR-0006VL-H4 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 08 Oct 2022 18:26:11 +0200 Original-Received: from localhost ([::1]:40650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohCeP-0006sI-UN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 08 Oct 2022 12:26:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohCeJ-0006s9-9J for bug-gnu-emacs@gnu.org; Sat, 08 Oct 2022 12:26:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42231) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohCeI-0001oS-IH for bug-gnu-emacs@gnu.org; Sat, 08 Oct 2022 12:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ohCeI-00081l-7m for bug-gnu-emacs@gnu.org; Sat, 08 Oct 2022 12:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 08 Oct 2022 16:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58367 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 58367-submit@debbugs.gnu.org id=B58367.166524634630829 (code B ref 58367); Sat, 08 Oct 2022 16:26:02 +0000 Original-Received: (at 58367) by debbugs.gnu.org; 8 Oct 2022 16:25:46 +0000 Original-Received: from localhost ([127.0.0.1]:41309 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ohCe1-00081B-Jj for submit@debbugs.gnu.org; Sat, 08 Oct 2022 12:25:45 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:45506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ohCdz-00080y-ID for 58367@debbugs.gnu.org; Sat, 08 Oct 2022 12:25:44 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id BEFB680758; Sat, 8 Oct 2022 12:25:37 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 8680B80470; Sat, 8 Oct 2022 12:25:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1665246335; bh=KPMR3kbxVP/8SZza1oyjuLjzPCkzPP0RAeEZoidDww8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=IqugfZnUQGHcAlr+YT9Fe4BwNVOobfNUJXeuEb9AZYXtr62IQSmYHSRDzeteLpAkh YTi6IiixmjD0Na+83glGNqLy4XUwQbSuQqv+5iR3ymaDEuUpDn8i8+lu1wGUa+Zn0f KRIFkT3Fs8e1uwJovPwS7YUXYrbouB3bqJdYG6dmakEYro7QEUwMbILwbFF+YhMs1Q IHerB0GqoSieAHGmXl2L2xTaOt5mCuEY0xVBz/5/6X2wEinozl+Ps06k2ld6rTqgDQ r2kpmTYc7tQOuDO8kEG77DPX14p7Vb6OvGybJ1DG7E3aEgvk+FPSaQJB7IJ75k09YO ZZd+q6KuadOTA== Original-Received: from pastel (65-110-220-202.cpe.pppoe.ca [65.110.220.202]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 52D211207BF; Sat, 8 Oct 2022 12:25:35 -0400 (EDT) In-Reply-To: <263dae3ce307236c2694a2bc0baa3f63@unbit.co.uk> (Richard Hopkins's message of "Fri, 07 Oct 2022 22:15:56 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:244920 Archived-At: > 2) A package where all files are in a single directory vs having > child directories. A package with child directories currently only > installs successfully if it's already extracted; the manual also says > they are allowed. I'm pretty sure I've successfully installed the Hyperbole package (which includes subdirectories) directly from GNU ELPA and I haven't heard complaints about the Proof-General (M|NonGNU)ELPA package (which relies even more heavily on subdirectories) either, so the problem is likely linked to some other "detail". [..time passes..] Thanks for the tarballs for the tests, they were very helpful. The patch also pointed in the right direction. I installed the patch below (plus regression tests) into `master`. [ Whether the name comparisons should be done on names that have gone through `expand-file-name` or not is a good question. Efficiency/simplicity suggests not to do that, and the code's history doesn't explain why it's done, but I have the vague recollection that it tries to handle some cases of funny file names, e.g. with .. in them. In the end I kept the `expand-file-name` version mostly so as to reduce the size of the change (and associated risk of regression). ] Stefan diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 4268f7d27a7..d619142d64c 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -930,7 +930,7 @@ package-untar-buffer (or (string-match regexp name) ;; Tarballs created by some utilities don't list ;; directories with a trailing slash (Bug#13136). - (and (string-equal dir name) + (and (string-equal (expand-file-name dir) name) (eq (tar-header-link-type tar-data) 5)) (error "Package does not untar cleanly into directory %s/" dir))))) (tar-untar-buffer)) @@ -1192,8 +1192,12 @@ 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 - (tar-header-name (car tar-parse-info)))) + (let* ((dir-name (named-let loop + ((filename (tar-header-name (car tar-parse-info)))) + (let ((dirname (file-name-directory filename))) + ;; The first file can be in a subdir: look for the top. + (if dirname (loop (directory-file-name dirname)) + (file-name-as-directory filename))))) (desc-file (package--description-file dir-name)) (tar-desc (tar-get-file-descriptor (concat dir-name desc-file)))) (unless tar-desc