From: Philip Kaludercic Date: Fri, 18 Aug 2023 10:10:02 +0000 (+0200) Subject: Add a command to revert back to the build-in version of package.el X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ce044bd9d66a77e65c9fbdf5a77ec9d30ce7611e;p=emacs.git 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 --- 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