From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Philip Kaludercic <philipk@posteo.net>
Newsgroups: gmane.emacs.bugs
Subject: bug#74556: 30.0.92;
 Package upgrade can fail and results in deleted package
Date: Thu, 28 Nov 2024 11:11:33 +0000
Message-ID: <87zflj62ai.fsf@posteo.net>
References: <87plmgq55e.fsf@daniel-mendler.de>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="40900"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: 74556@debbugs.gnu.org
To: Daniel Mendler <mail@daniel-mendler.de>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 28 12:12:27 2024
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
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 <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1tGcRe-000ATo-SP
	for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 28 Nov 2024 12:12:27 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1tGcRJ-0004jz-G5; Thu, 28 Nov 2024 06:12:05 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1tGcRH-0004jp-23
 for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2024 06:12:03 -0500
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1tGcRG-0008QF-Pg
 for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2024 06:12:02 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
 d=debbugs.gnu.org; s=debbugs-gnu-org; 
 h=MIME-Version:Date:References:In-Reply-To:From:To:Subject;
 bh=fptF4AB4qQcSBtQmOtlxzYcdox6xilTbHVAIXJZBgYg=; 
 b=nBSiO1Dljpc+coQzqPW6SX6TwgEAmO2EPULVFpJFFbnWK3l1K7M85dVS/gGkALWRz7AyqdI4IWTWI+OREixZT0QuGLwH/6X8c9piRCk3X0V1YmKN9Aga7RXYB71/ze2K5qnpAWIEb6jDxCKzG5Z8Xx1bLa+rwsfBU8DjRchF0gRA47BL499SM6EpiJawAE0Rpml/1oBjkdhiOTwjDRdTlfOBTZT9EOtd5q2AI75QqBB1vYWyje8vtdakgfne6usCUMAMwg00hSkylrWZD1xDNLC4GCY9x8IrXF5oXAPdzxYnL5VtDUUe+R+AOXAlcTOIneHvGN7/qbsgxWWJ/jJWBQ==;
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1tGcRG-0002qV-KX
 for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2024 06:12:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Philip Kaludercic <philipk@posteo.net>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Thu, 28 Nov 2024 11:12:02 +0000
Resent-Message-ID: <handler.74556.B74556.173279230510908@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 74556
X-GNU-PR-Package: emacs
Original-Received: via spool by 74556-submit@debbugs.gnu.org id=B74556.173279230510908
 (code B ref 74556); Thu, 28 Nov 2024 11:12:02 +0000
Original-Received: (at 74556) by debbugs.gnu.org; 28 Nov 2024 11:11:45 +0000
Original-Received: from localhost ([127.0.0.1]:36921 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1tGcQy-0002ps-Rg
 for submit@debbugs.gnu.org; Thu, 28 Nov 2024 06:11:45 -0500
Original-Received: from mout02.posteo.de ([185.67.36.66]:55765)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <philipk@posteo.net>) id 1tGcQw-0002pT-7p
 for 74556@debbugs.gnu.org; Thu, 28 Nov 2024 06:11:43 -0500
Original-Received: from submission (posteo.de [185.67.36.169]) 
 by mout02.posteo.de (Postfix) with ESMTPS id EBB90240101
 for <74556@debbugs.gnu.org>; Thu, 28 Nov 2024 12:11:35 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1732792295; bh=dCLYOH1H43Z9ytRoMgMLaUjMCzQOJhSPXNC8pp4Wipc=;
 h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version:
 Content-Type:From;
 b=d6sQu6KjCbv3r92vu7126KCi77lY3EVnThEw5/9csiLJTete8UBzFZMdXRGZqm+u4
 DIa0QDX4OGR/CvlYF13h4ReO1QQF2kVzRX4OGf3M2p2vmQC9AFSxPqmmO4i/YbGVpQ
 7bLKzgk/4ci2zclhxeHQ0h+qa0e+EwZlCDXngPbzw790dxoEsUlPn4hK+1gOqbDSbO
 C6hSrW2K9Irn4n8MoPUTo0V3/R/1xIfQ7zW2uB90lNpe8FiETkBKIipImt4SfB6vr8
 ob6F52TX3lBaYCQVBjiQdjr7qrYCjpdDN5ki4Zd0EfgA/rCRpMpNOEINIJcOFFQZIS
 u0ZMMws2sCWmQ==
Original-Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4XzYXl0T4jz9rxK;
 Thu, 28 Nov 2024 12:11:33 +0100 (CET)
In-Reply-To: <87plmgq55e.fsf@daniel-mendler.de> (Daniel Mendler's message of
 "Wed, 27 Nov 2024 12:37:17 +0100")
Autocrypt: addr=philipk@posteo.net; keydata=
 mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo
 aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0
 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI
 BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0
 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB
 BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE
 Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK
 NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof
 z4oM
OpenPGP: id=philipk@posteo.net;
 url="https://keys.openpgp.org/vks/v1/by-email/philipk@posteo.net";
 preference=signencrypt
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" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:296051
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/296051>

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Daniel Mendler <mail@daniel-mendler.de> writes:

> Package upgrade can fail when the package metadata is out of sync. The
> upgrade process first deletes the package, tries to download the new
> version. If the download fails for some reason (metadata out of sync or
> the file not available), the upgrade aborts but the earlier package
> deletion is not rolled back as one would expect for an upgrade
> transaction. Ideally the download would be performed first such that the
> upgrade process wouldn't lead to a missing package.
>
> I just executed M-x package-upgrade-all. The following messages appeared
> in the log:
>
> Package =E2=80=98<package>-<old-version>=E2=80=99 deleted.
> Contacting host: elpa.gnu.org:443
> package--with-response-buffer-1:
> https://elpa.gnu.org/devel/<pkgname>-<new-version>.tar: No Data

I cannot test this out right now, but it seems that the fix should be
straight-forward


--=-=-=
Content-Type: text/plain
Content-Disposition: inline

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 438af781393..46b2d7580c1 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2268,12 +2268,16 @@ package-upgrade
     ;; `pkg-desc' will be nil when the package is an "active built-in".
     (if (and pkg-desc (package-vc-p pkg-desc))
         (package-vc-upgrade pkg-desc)
-      (when pkg-desc
-        (package-delete pkg-desc 'force 'dont-unselect))
       (package-install package
                        ;; An active built-in has never been "selected"
                        ;; before.  Mark it as installed explicitly.
-                       (and pkg-desc 'dont-select)))))
+                       (and pkg-desc 'dont-select))
+      ;; We delete the old package via the descriptor after installing
+      ;; the new package to avoid losing the package if there issues
+      ;; during installation (Bug#74556).
+      (cl-assert (package-desc-dir pkg-desc))
+      (when pkg-desc
+        (package-delete pkg-desc 'force 'dont-unselect)))))
 
 (defun package--upgradeable-packages (&optional include-builtins)
   ;; Initialize the package system to get the list of package

--=-=-=
Content-Type: text/plain


It might make sense to try and "deactivate" a package before installing
the new package.  Looking into some second-try fallback for
package-install to refresh the package index if a package was not found
would also be a good idea ^^

--=-=-=--