unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ioannis Kappas <ioannis.kappas@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 48137@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#48137: 27.2; `package-install-file' fails when loading a package file with DOS line endings
Date: Sun, 16 May 2021 10:09:07 +0100	[thread overview]
Message-ID: <CAMRHuGBMyYJMVVUp-gGMMukwSxwBFZLj6oVp6v8dn+gADU2pSQ@mail.gmail.com> (raw)
In-Reply-To: <CAMRHuGCqdrmS+t7vnXXDoyRZ9rYYjZYk-ZAWH1B2m845P5Kzeg@mail.gmail.com>

On Sat, May 15, 2021 at 2:52 PM Ioannis Kappas <ioannis.kappas@gmail.com> wrote:
> I shall have a look next whether we could always load the package with
> `insert-file-contents-literally' but parse headers with the correct
> encoding (`find-operation-coding-system' looks like a promising fn
> to determine the correct encoding from a literal file buffer).

Please find below a patch to read package headers from a temporarily
decoded buffer, while keeping the literal buffer (which will be used
to install the package) intact.

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index ecb2573cab..a7a11bc6cc 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2122,8 +2122,22 @@ package-install-from-buffer
             ((derived-mode-p 'tar-mode)
              (package-tar-file-info))
             (t
-             (save-excursion
-              (package-buffer-info)))))
+             ;; Package headers should be parsed from decoded text
+             ;; (see Bug#48137) where possible.
+             (if (and (eq buffer-file-coding-system 'no-conversion)
+                      buffer-file-name)
+                 (let* ((package-buffer (current-buffer))
+                        (decoding-system
+                         (car (find-operation-coding-system
'insert-file-contents
+                                                            (cons
buffer-file-name
+
package-buffer)))))
+                   (with-temp-buffer
+                     (insert-buffer-substring package-buffer)
+                     (decode-coding-region (point-min) (point-max)
decoding-system)
+                     (package-buffer-info)))
+
+               (save-excursion
+                 (package-buffer-info))))))
          (name (package-desc-name pkg-desc)))
     ;; Download and install the dependencies.
     (let* ((requires (package-desc-reqs pkg-desc))
@@ -2148,6 +2162,7 @@ package-install-file
           (setq default-directory file)
           (dired-mode))
       (insert-file-contents-literally file)
+      (set-visited-file-name file)
       (when (string-match "\\.tar\\'" file) (tar-mode)))
     (package-install-from-buffer)))


Notes:
- The logic can be moved to `package-buffer-info'.
- Ideally, I would have liked to only copy and header section to the
  temporary buffer for decoding, but the `(while (comment-forward))`
  trick that I've tried fails to move past the headers section in
  literal buffers with CRLF pairs. Perhaps it is better after all not
  to try and use any regex ops on a 'binary buffer?

thanks





  reply	other threads:[~2021-05-16  9:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01 11:38 bug#48137: 27.2; `package-install-file' fails when loading a package file with DOS line endings Ioannis Kappas
2021-05-01 11:48 ` Ioannis Kappas
2021-05-01 12:15   ` Eli Zaretskii
2021-05-01 13:51     ` Stefan Monnier
2021-05-03 17:47       ` Ioannis Kappas
2021-05-03 18:23         ` Stefan Monnier
2021-05-03 18:33           ` Eli Zaretskii
2021-05-03 18:49             ` Ioannis Kappas
2021-05-03 18:52               ` Eli Zaretskii
2021-05-03 20:12                 ` Stefan Monnier
2021-05-04 11:39                   ` Eli Zaretskii
2021-05-03 19:41             ` Stefan Monnier
2021-05-04 11:34               ` Eli Zaretskii
2021-05-04 15:57                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-04 16:14                   ` Eli Zaretskii
2021-05-04 16:27                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-04 16:51                       ` Eli Zaretskii
2021-05-05  7:03                         ` Ioannis Kappas
2021-05-05 12:01                           ` Eli Zaretskii
     [not found]                             ` <CAMRHuGAi9+q-MKRGPxLqxdP_7SSF4Nqj+JuSsZigviAQs_d7Rw@mail.gmail.com>
2021-05-06  6:55                               ` Ioannis Kappas
2021-05-06  8:12                                 ` Eli Zaretskii
2021-05-06 13:27                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-06 15:26                                   ` Eli Zaretskii
2021-05-11  6:52                                     ` Ioannis Kappas
2021-05-11 12:55                                       ` Eli Zaretskii
2021-05-15 13:52                                         ` Ioannis Kappas
2021-05-16  9:09                                           ` Ioannis Kappas [this message]
2021-05-29  8:20                                             ` Eli Zaretskii
2021-05-29 13:59                                               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-29 14:09                                                 ` Eli Zaretskii
2021-06-06  9:11                                                   ` Ioannis Kappas
2021-07-20 13:54                                                     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMRHuGBMyYJMVVUp-gGMMukwSxwBFZLj6oVp6v8dn+gADU2pSQ@mail.gmail.com \
    --to=ioannis.kappas@gmail.com \
    --cc=48137@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).