From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#48137: 27.2; `package-install-file' fails when loading a package file with DOS line endings Date: Sat, 01 May 2021 15:15:19 +0300 Message-ID: <834kfmabvs.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11392"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 48137@debbugs.gnu.org To: Ioannis Kappas , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 01 14:16:40 2021 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 1lcoY3-0002sV-Aj for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 01 May 2021 14:16:39 +0200 Original-Received: from localhost ([::1]:33710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcoY2-0000HC-EO for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 01 May 2021 08:16:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcoXS-0008SA-Lg for bug-gnu-emacs@gnu.org; Sat, 01 May 2021 08:16:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53017) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lcoXS-00059T-DZ for bug-gnu-emacs@gnu.org; Sat, 01 May 2021 08:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lcoXS-0004ts-8u for bug-gnu-emacs@gnu.org; Sat, 01 May 2021 08:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 01 May 2021 12:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48137 X-GNU-PR-Package: emacs Original-Received: via spool by 48137-submit@debbugs.gnu.org id=B48137.161987133218799 (code B ref 48137); Sat, 01 May 2021 12:16:02 +0000 Original-Received: (at 48137) by debbugs.gnu.org; 1 May 2021 12:15:32 +0000 Original-Received: from localhost ([127.0.0.1]:36324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lcoWx-0004t9-QK for submit@debbugs.gnu.org; Sat, 01 May 2021 08:15:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38336) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lcoWw-0004t3-0x for 48137@debbugs.gnu.org; Sat, 01 May 2021 08:15:30 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:42737) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcoWq-0004oZ-DA; Sat, 01 May 2021 08:15:24 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4218 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lcoWp-0007VQ-Oe; Sat, 01 May 2021 08:15:24 -0400 In-Reply-To: (message from Ioannis Kappas on Sat, 1 May 2021 12:48:06 +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:205340 Archived-At: > From: Ioannis Kappas > Date: Sat, 1 May 2021 12:48:06 +0100 > > The error appears to be a side effect of `package-install-file' > loading the file literally with `insert-file-contents-literally' and > thus setting the coding system to 'no-conversion (as reported by the > `buffer-file-coding-system' variable ). This means that for a DOS > encoded file the ?\r (Carriage Return) in the DOS line ending ?\r?\n > will be treated as an independent control character rather than > consumed as part of the line ending as far as Emacs is concerned. > > This extra control character in our case appears in the version number > extracted with `lm-header' (.e.g. "0.1^M"), failing the > `version-to-list' conversion in > `package-buffer-info'->`package-strip-rcs-id', resulting to the error > that it lacks a version header. > > It is not obvious why `package-install-file' loads package files > literally at all times, `package--with-response-buffer-1' also does > the same. If the reason turns out not to be important, then a possible > solution could be to load package files metaphorically: > > 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. > Another solution could be to upgrade the 'lisp-mnt package to ignore > ?\r characters. Looking at the `lm-header' fn invoked by > `package-buffer-info', it does have a list of characters to stop at > when looking for a header, we can thus add the carriage return to the > list: > > diff --git a/lisp/emacs-lisp/lisp-mnt.el b/lisp/emacs-lisp/lisp-mnt.el > index 9cba232e16..3eb493d286 100644 > --- a/lisp/emacs-lisp/lisp-mnt.el > +++ b/lisp/emacs-lisp/lisp-mnt.el > @@ -267,7 +267,7 @@ lm-header > (if (save-excursion > (skip-chars-backward "^$" (match-beginning 0)) > (= (point) (match-beginning 0))) > - "[^\n]+" "[^$\n]+"))) > + "[^\n\r]+" "[^$\n\r]+"))) This is better, but IMO the code should be rewritten not to allow a lone CR character, only either a lone LF or the CRLF pair. > 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? Thanks.