]> git.eshelyaron.com Git - emacs.git/commitdiff
Attempt to install package first when upgrading
authorPhilip Kaludercic <philipk@posteo.net>
Sat, 7 Dec 2024 19:02:00 +0000 (20:02 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sun, 15 Dec 2024 16:35:07 +0000 (17:35 +0100)
* lisp/emacs-lisp/package.el (package-upgrade): Swap the
'package-install' and the 'package-delete' invocations.
(Bug#74556)

(cherry picked from commit 3d8e49c41a66a7f05cb96f84e2a10f0f308ac9ca)

lisp/emacs-lisp/package.el

index 7a8e5a685d9b0593f951c9b4fcf9373a071d198b..31df3c2cc44823ff0afe58c1aa493fc7f44c833d 100644 (file)
@@ -2268,12 +2268,16 @@ had been enabled."
     ;; `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).
+      (when pkg-desc
+        (cl-assert (package-desc-dir 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