Subject: bug#48137: 27.2; `package-install-file' fails when loading a package file with DOS line endings

From: Stefan Monnier <[email-masked]>
Date: Sat, 01 May 2021 09:51:03 -0400

>> diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
>> index ecb2573cab..98d63f1aff 100644
>> --- a/lisp/emacs-lisp/package.el
>> +++ b/lisp/emacs-lisp/package.el
>> @@ -2147,8 +2147,11 @@ package-install-file
>>          (progn
>>            (setq default-directory file)
>>            (dired-mode))
>> -      (insert-file-contents-literally file)
>> -      (when (string-match "\\.tar\\'" file) (tar-mode)))
>> +      (if (string-match "\\.tar\\'" file)
>> +          (progn
>> +            (insert-file-contents-literally file)
>> +            (tar-mode))
>> +        (insert-file-contents file)))
>
> I don't think this is TRT, because insert-file-contents also decodes
> the character encoding, not just the EOL encoding.

I think for `.el` files it's actually correct to decode the character
encoding here (it's maybe not necessary, but I think it's at least
as correct as what we do now, since `package-install-from-buffer`
expects a "normal" buffer, hence for `.el` buffers it expects one where
characters have been decoded).

BTW, this code needs some love, for example to handle `.tar.lz` files.

>> Or is it perhaps that packages should only be written with Unix line
>> endings and thus the solution is to update documentation and create
>> more targeted error messages?
> This is probably the best, IMO.  Stefan?

It sounds like a good idea as well, yes.

        Stefan