emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/elpa-package ce044bd9d66 2/3: Add a command to revert back to th


From: Philip Kaludercic
Subject: feature/elpa-package ce044bd9d66 2/3: Add a command to revert back to the build-in version of package.el
Date: Fri, 18 Aug 2023 14:27:39 -0400 (EDT)

branch: feature/elpa-package
commit ce044bd9d66a77e65c9fbdf5a77ec9d30ce7611e
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add a command to revert back to the build-in version of package.el
    
    * lisp/emacs-lisp/package.el (package-revert-to-builtin): Add function
---
 lisp/emacs-lisp/package.el | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 5743b6f504e..56024c7b686 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]