]> git.eshelyaron.com Git - emacs.git/commitdiff
Add a command to revert back to the build-in version of package.el
authorPhilip Kaludercic <philipk@posteo.net>
Fri, 18 Aug 2023 10:10:02 +0000 (12:10 +0200)
committerPhilip Kaludercic <philipk@posteo.net>
Fri, 18 Aug 2023 18:26:10 +0000 (20:26 +0200)
* lisp/emacs-lisp/package.el (package-revert-to-builtin): Add function

lisp/emacs-lisp/package.el

index 5743b6f504ecc2cd4ae8cdc32d4dc5d59f4f922b..56024c7b686116c53e040535ac329c3ddd29d982 100644 (file)
@@ -4692,6 +4692,39 @@ DESC must be a `package-desc' object."
       (cadr (assq pkg-name package-alist))
       (cadr (assq pkg-name package-archive-contents))))
 
+;;;; Error Recovery
+
+;;;###autoload
+(progn
+  ;; In case there is an issue with package.el being installed from
+  ;; ELPA, this command should help revert to the built-in version,
+  ;; that is assumed to be more reliable.
+  (defun package-revert-to-builtin ()
+    "Force delete a newer installation of package.el from ELPA.
+This command is to be used in case there are issues with an
+updated version of package.el, that might be resolved by
+reverting to the bundled version of package.el"
+    (interactive)
+    (let* ((elpa-dir (or (bound-and-true-p package-user-dir)
+                         (locate-user-emacs-file "elpa")))
+           (files (directory-files
+                   elpa-dir t
+                   ;; THINKME: Should we be concerned about packages
+                   ;; with pathological names like "package-9"?
+                   (rx bos "package-" (+ digit) (* "." (+ digit))))))
+      (if (null files)
+          (message "No newer version of package.el from ELPA found.")
+        (when (yes-or-no-p "Detected a newer version of package.el, delete it?")
+          (dolist (f files)
+            (if (file-directory-p f)
+                (delete-directory f t)
+              (delete-file f)))
+          (require 'package nil t)
+          (when (boundp 'package-selected-packages)
+            (customize-set-variable
+             'package-selected-packages
+             (remq 'package package-selected-packages))))))))
+
 (provide 'package)
 
 ;;; package.el ends here