From 08bff310812d8d0821c7b283a2d5e0fdca87f1ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerd=20M=C3=B6llmann?= Date: Tue, 25 Oct 2022 14:04:36 +0200 Subject: [PATCH] Prevent accidentally unregistering packages * lisp/emacs-lisp/pkg.el (pkg--remove-from-registry): Check for package being eq to a registered package. --- lisp/emacs-lisp/pkg.el | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/pkg.el b/lisp/emacs-lisp/pkg.el index 47317fdf532..56c191f7d08 100644 --- a/lisp/emacs-lisp/pkg.el +++ b/lisp/emacs-lisp/pkg.el @@ -161,11 +161,18 @@ Otherwise, NAME must be the name of a registered package." (mapc (lambda (name) (puthash name package *package-registry*)) (package-%nicknames package))) -(defun pkg--remove-from-registry (package) +(cl-defun pkg--remove-from-registry (package) "Remove PACKAGE from the package registry." - (remhash (package-%name package) *package-registry*) - (mapc (lambda (name) (remhash name *package-registry*)) - (package-%nicknames package))) + ;; Note that an unregistered package might have the same name or + ;; nickname as a registered package. Prevent deleting such a + ;; package from unregistering some other package. + (let ((names ())) + (maphash (lambda (n p) + (when (eq p package) + (push n names))) + *package-registry*) + (dolist (n names) + (remhash n *package-registry*)))) (defun pkg--package-or-default (package) "Return the package object denoted by PACKAGE. -- 2.39.2