Subject: bug#78636: 30.1; package-install-file errors with some tar files

From: Andy Rosen <[email-masked]>
Date: Tue, 10 Jun 2025 19:32:54 +0000

On Jun 9, 2025, at 7:46 AM, Philip Kaludercic <[email-masked]> wrote:
> 
> Eli Zaretskii <[email-masked]> writes:
> 
>>> Date: Thu, 29 May 2025 15:56:31 +0000
>>> From:  Andy Rosen via "Bug reports for GNU Emacs,
>>> the Swiss army knife of text editors" <[email-masked]>
>>> 
>>> I propose adding a 'condition-case' to 'package-install-file' to return a friendly message.
>>> 
>>> diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
>>> index 82fcf439a11..01f659e6982 100644
>>> --- a/lisp/emacs-lisp/package.el
>>> +++ b/lisp/emacs-lisp/package.el
>>> @@ -2439,8 +2439,10 @@ directory."
>>>       (insert-file-contents-literally file)
>>>       (set-visited-file-name file)
>>>       (set-buffer-modified-p nil)
>>> -      (when (string-match "\\.tar\\'" file) (tar-mode)))
>>> -    (package-install-from-buffer)))
>>> +      (when (string-match "\\.tar\\'" file) (tar-mode)
>                                                ^
> Please break the line here.  I initially missed the major-mode switch,
> which confused me.

Like this?

      (when (string-match "\\.tar\\'" file)
        (tar-mode)

It’s a single line in the current source.  Yes, it makes more sense to split it.

> Also, can't we use `tar-header-block-tokenize' or some other function to
> directly check if the file is a valid archive, instead of relying on
> downstream signals being raised?

I don’t think we can use `tar-header-block-tokenize'.  The file is a valid tar archive, it’s just not a valid package file.  From tar-mode’s point of view everything is correct.

`tar-get-file-descriptor’ is a possibility.  Part of this bug is `tar-get-file-descriptor’ does not check if `tar-header-name’ matched with anything in `tar-parse-info'.  In this case it does not, so `tar-get-file-descriptor’ passes nil to `tar--check-descriptor’, then to `tar--describe-as-link’, then to `tar-header-link-type’.  `tar-header-link-type’ throws "wrong-type-argument”.

Checking for (and returning) nil in `tar-get-file-descriptor’ prevents the error, and ends up with "No package descriptor file found” in the echo area.

-Andy