Subject: bug#20309: bug#21319: `package-install-file' fails with CRLF (Windows) line endings

From: Stefan Kangas <[email-masked]>
Date: Tue, 22 Oct 2019 03:04:59 +0200

steckerhalter <[email-masked]> writes:

> package.el contains this code:
>
> (defun package-install-file (file)
>   "Install a package from a file.
> The file can either be a tar file or an Emacs Lisp file."
>   (interactive "fPackage file name: ")
>   (with-temp-buffer
>     (insert-file-contents-literally file)
>     (when (string-match "\\.tar\\'" file) (tar-mode))
>     (package-install-from-buffer)))
>
> Since `insert-file-contents-literally' does not do any conversion
> `package-buffer-info' fails to parse the info if the file is .el and
> contains CRLF line endings. It then errors out with:
>
> Debugger entered--Lisp error: (error "Package lacks a \"Version\" or
> \"Package-Version\" header")
>   signal(error ("Package lacks a \"Version\" or \"Package-Version\" header"))
>   error("Package lacks a \"Version\" or \"Package-Version\" header")
>   package-buffer-info()
>
> This affects all recent Emacs versions (including trunk).

This was reported 4 years ago, but unfortunately never got a reply at
the time.

Are you still seeing this on a recent version of Emacs?  If yes, could
you please provide a minimal example file which fails to install?

Also, why does your file have these line endings in the first place?
Was this file written in Emacs?  I'm trying to understand if this is
an important use case or the common scenario for users of MS-Windows,
since I don't use it myself.

Best regards,
Stefan Kangas