Only remove non system pkg

Added "configuration-layer//system-package?" based on package-delete
(pretty much a direct partial copy-paste) so that
"configuration-layer//package-delete" can check if package is a
system package

No crash on spacemacs boot (with unused system-package present).
Though right now "configuration-layer//package-delete" only ignores system
packages instead of reporting them. Not entierly what @nbraud proposed,
but insufficient err-logging is a significantly smaller issue.

Fixes #11160
This commit is contained in:
William Cedervall 2019-01-07 04:49:08 +01:00 committed by Maximilian Wolff
parent dec350eb84
commit 52d5d9d98f
No known key found for this signature in database
GPG Key ID: 2DD07025BFDBD89A
1 changed files with 12 additions and 2 deletions

View File

@ -2352,15 +2352,25 @@ depends on it."
(unless (string-empty-p version-string)
(version-to-list version-string))))
(defun configuration-layer//system-package? (pkg-desc)
"Cheks if package is a system package"
(not (string-prefix-p
(file-name-as-directory
(expand-file-name package-user-dir))
(expand-file-name
(package-desc-dir pkg-desc)))))
(defun configuration-layer//package-delete (pkg-name)
"Delete package with name PKG-NAME."
(cond
((version<= "25.0.50" emacs-version)
(let ((p (cadr (assq pkg-name package-alist))))
;; add force flag to ignore dependency checks in Emacs25
(when p (package-delete p t t))))
(when (not (configuration-layer//system-package? p))
(package-delete p t t))))
(t (let ((p (cadr (assq pkg-name package-alist))))
(when p (package-delete p))))))
(when (not (configuration-layer//system-package? p))
(package-delete p))))))
(defun configuration-layer/delete-orphan-packages (packages)
"Delete PACKAGES if they are orphan."