unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Sylvain Bougerel <sylvain.bougerel.devel@gmail.com>
To: Philip Kaludercic <philipk@posteo.net>
Cc: 66985@debbugs.gnu.org
Subject: bug#66985: 29.1; Issue with `package.el` upgrading builtin (edge-case)
Date: Sat, 11 Nov 2023 01:05:45 +0800	[thread overview]
Message-ID: <CA+qKf8TV1xnM1Qk1nXvU8nUC=cpHy4fMnimhcMB2k=BcyW+Sog@mail.gmail.com> (raw)
In-Reply-To: <CA+qKf8QP2FZSZjwkM4Xi57gB9O86pNZtOhbjjxdPD9ZpyUaKUw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3758 bytes --]

> Here the issue shows itself, `seq` is now requested for installation,
> which is incorrect, since Emacs already have the latest version.

TL;DR I believe I have found the bug in `package-compute-transaction'.
It misses the
assignment to the newer version of the package that was already in the list of
packages to be installed.


Some details. The following 1-line change fixes it for me (added context around
for readability), in `package-compute-transaction':

       (when already
         (if (version-list-<= next-version (package-desc-version already))
             ;; `next-pkg' is already in `packages', but its position there
             ;; means it might be installed too late: remove it from there, so
             ;; we re-add it (along with its dependencies) at an earlier place
             ;; below (bug#16994).
             (if (memq already seen)     ;Avoid inf-loop on dependency cycles.
                 (message "Dependency cycle going through %S"
                          (package-desc-full-name already))
               (setq packages (delq already packages))
+              (setq next-version (package-desc-version already))
               (setq already nil))
           (error "Need package `%s-%s', but only %s is being installed"
                  next-pkg (package-version-join next-version)
                  (package-version-join (package-desc-version already)))))


The issue occurs in the following scenario:
    - Package A (version a), noted A(a), depends on packages B(z), then C(y)
    - Package C(y) depends on package B(x), which is an _older_
version than B(z)
    - Neither A(a), B(z) nor C(y) are installed (the state of B(x) is
irrelevant)

`package-compute-transaction' will consider first the requirement B(z) and push
it to PACKAGES; then the requirement C(y) is pushed. It will then consider
C(y)'s requirement B(x). Since B is ALREADY seen, it first deletes B(z) from
PACKAGES, expecting to push in front of PACKAGES later, in `cond''s body (so
that B is installed earlier than both A and C). **But it fails to set
NEXT-VERSION to the newer B(z) and retains B(x)'s older version instead.**
That's the edge-case of the bug.

The fix is to set NEXT-VERSION to the version of the equal or newer package,
which is always the one already present in PACKAGE, given the preceding `if'
condition.

In my case, this result in the strange disappearance of `seq' from PACKAGES when
`compat' is not installed, because the older version of `seq' is already
installed and it's enough to meet the requirement of one of the transitive
dependencies of `git-commit', which is `compat'. On the other end, if `compat'
is installed, it's requirements are not checked and thus `seq' remains in the
list.

I provided the format-patch for it in the attachment, but it's the
same single line
of code change as shown above. I have no knowledge on how to submit it other
than by this email, any guidance or direction is appreciated.



Though interestingly, that was actually not the root cause of my personal
problem. I didn't expect `seq' to be installed in the first place, it is
built-in and `package-install-upgrade-built-in' is `nil' on my setup. (I was
expecting to find an issue revolving around this, and stumbled on this one :) )

Do you think I have misunderstood the purpose of
`package-install-upgrade-built-in'? Should the `package-compute-transaction` be
fixed to take it into account? It is not too difficult to do, however I think
this would be a rather impacting change, as users may have gotten used to their
built-in packages dependencies being upgraded without friction, even when they
are built-in.

Looking for another opinion, I lack context on the purpose of
`package-install-upgrade-built-in`.

    - Sylvain

[-- Attachment #2: 0001-Fix-next-version-in-package-compute-transaction-bug-.patch --]
[-- Type: text/x-patch, Size: 992 bytes --]

From c6d40924d1bf3379308bfbef69acbab8e8877c4b Mon Sep 17 00:00:00 2001
From: Sylvain Bougerel <sylvain.bougerel.devel@gmail.com>
Date: Sat, 11 Nov 2023 00:14:41 +0800
Subject: [PATCH] Fix next-version in package-compute-transaction (bug#66985)

---
 lisp/emacs-lisp/package.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index e23a61c58a4..a8e263bc074 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1908,6 +1908,7 @@ SEEN is used internally to detect infinite recursion."
                 (message "Dependency cycle going through %S"
                          (package-desc-full-name already))
               (setq packages (delq already packages))
+              (setq next-version (package-desc-version already))
               (setq already nil))
           (error "Need package `%s-%s', but only %s is being installed"
                  next-pkg (package-version-join next-version)
-- 
2.42.0


  reply	other threads:[~2023-11-10 17:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 13:11 bug#66985: 29.1; Issue with `package.el` upgrading builtin (edge-case) Sylvain Bougerel
2023-11-07 15:27 ` Sylvain Bougerel
2023-11-08  1:01   ` Sylvain Bougerel
2023-11-08  7:51 ` Philip Kaludercic
2023-11-08 16:30   ` Sylvain Bougerel
2023-11-10 17:05     ` Sylvain Bougerel [this message]
2023-11-15 13:06       ` Sylvain Bougerel
2023-11-15 13:30       ` Eli Zaretskii
2023-11-16  7:25       ` Philip Kaludercic
2023-11-17  9:37         ` Sylvain Bougerel
2023-11-27 17:18           ` Philip Kaludercic

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='CA+qKf8TV1xnM1Qk1nXvU8nUC=cpHy4fMnimhcMB2k=BcyW+Sog@mail.gmail.com' \
    --to=sylvain.bougerel.devel@gmail.com \
    --cc=66985@debbugs.gnu.org \
    --cc=philipk@posteo.net \
    /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).