all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: emacs-devel@gnu.org
Subject: Re: package.el dependencies
Date: Sun, 25 Jan 2015 16:48:43 +0100	[thread overview]
Message-ID: <87y4oqg8tg.fsf@gmail.com> (raw)
In-Reply-To: <jwvmw56syhb.fsf-monnier+emacs@gnu.org>


Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>>>> 1) Prevent (or warn) deleting a package if it is already used by another
>>>> package as dependency.
>>> That'd be nice.
>> Fixed,
>
> Thanks Thierry.
>
>> assuming that when upgrading a package, deletion of old version
>> is made AFTER installing new version.
>
> Good,

Here the patch:

--8<---------------cut here---------------start------------->8---
20c8e5d05f8e8e8996cf80f03f35335b328fdd94 HEAD package_autoremove
Author: Thierry Volpiatto <thierry.volpiatto@gmail.com>
Date:   Sun Jan 25 10:13:28 2015 +0100

    Prevent deleting a package needed as dependency by another package.
    
    * lisp/emacs-lisp/package.el (package-used-elsewhere-p): New.
    (package-delete): Use it.

1 file changed, 30 insertions(+), 18 deletions(-)
 lisp/emacs-lisp/package.el | 48 +++++++++++++++++++++++++++++-----------------

	Modified   lisp/emacs-lisp/package.el
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 88fc950..6923de5 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1388,26 +1388,38 @@ The file can either be a tar file or an Emacs Lisp file."
       (when (string-match "\\.tar\\'" file) (tar-mode)))
     (package-install-from-buffer)))
 
+(defun package-used-elsewhere-p (pkg)
+  "Check if PKG is used elsewhere as dependency.
+Argument PKG is a symbol."
+  (cl-loop with alist = (remove (assoc pkg package-alist) package-alist)
+           for p in alist thereis
+           (member pkg (mapcar 'car (package-desc-reqs (cadr p))))))
+
 (defun package-delete (pkg-desc)
   (let ((dir (package-desc-dir pkg-desc)))
-    (if (not (string-prefix-p (file-name-as-directory
-                               (expand-file-name package-user-dir))
-                              (expand-file-name dir)))
-        ;; Don't delete "system" packages.
-	(error "Package `%s' is a system package, not deleting"
-               (package-desc-full-name pkg-desc))
-      (delete-directory dir t t)
-      ;; Remove NAME-VERSION.signed file.
-      (let ((signed-file (concat dir ".signed")))
-	(if (file-exists-p signed-file)
-	    (delete-file signed-file)))
-      ;; Update package-alist.
-      (let* ((name (package-desc-name pkg-desc))
-             (pkgs (assq name package-alist)))
-        (delete pkg-desc pkgs)
-        (unless (cdr pkgs)
-          (setq package-alist (delq pkgs package-alist))))
-      (message "Package `%s' deleted." (package-desc-full-name pkg-desc)))))
+    (cond ((not (string-prefix-p (file-name-as-directory
+                                  (expand-file-name package-user-dir))
+                                 (expand-file-name dir)))
+           ;; Don't delete "system" packages.
+           (error "Package `%s' is a system package, not deleting"
+                  (package-desc-full-name pkg-desc)))
+          ((package-used-elsewhere-p (elt pkg-desc 1))
+           ;; Don't delete packages used as dependency elsewhere.
+           (error "Package `%s' is used elsewhere as dependency, not deleting"
+                  (package-desc-full-name pkg-desc)))
+          (t 
+           (delete-directory dir t t)
+           ;; Remove NAME-VERSION.signed file.
+           (let ((signed-file (concat dir ".signed")))
+             (if (file-exists-p signed-file)
+                 (delete-file signed-file)))
+           ;; Update package-alist.
+           (let* ((name (package-desc-name pkg-desc))
+                  (pkgs (assq name package-alist)))
+             (delete pkg-desc pkgs)
+             (unless (cdr pkgs)
+               (setq package-alist (delq pkgs package-alist))))
+           (message "Package `%s' deleted." (package-desc-full-name pkg-desc))))))
 
 (defun package-archive-base (desc)
   "Return the archive containing the package NAME."
--8<---------------cut here---------------end--------------->8---

-- 
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 



  reply	other threads:[~2015-01-25 15:48 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 13:37 package.el dependencies Thierry Volpiatto
2015-01-23 13:46 ` Dmitry Gutov
2015-01-23 14:12   ` Ivan Shmakov
2015-01-23 20:40 ` Stefan Monnier
2015-01-23 21:02   ` Thierry Volpiatto
2015-01-24  0:50     ` Artur Malabarba
2015-01-24  4:55       ` Stefan Monnier
2015-01-25  6:51         ` Thierry Volpiatto
2015-01-26  7:17         ` Thierry Volpiatto
2015-01-26  9:19           ` Artur Malabarba
2015-01-26  9:54             ` Thierry Volpiatto
2015-01-26 12:46               ` Artur Malabarba
2015-01-26 14:52           ` Stefan Monnier
2015-01-27  6:10             ` Thierry Volpiatto
2015-01-27 11:52               ` Artur Malabarba
2015-01-25  9:18   ` Thierry Volpiatto
2015-01-25 14:54     ` Stefan Monnier
2015-01-25 15:48       ` Thierry Volpiatto [this message]
2015-01-25 17:10         ` Dmitry Gutov
2015-01-25 18:32           ` Stephen Leake
2015-01-25 18:21         ` Artur Malabarba
2015-01-26  4:48           ` Thierry Volpiatto
2015-01-26 12:35             ` Artur Malabarba
2015-01-26 12:53         ` Artur Malabarba
2015-01-26 15:22   ` Thierry Volpiatto
2015-01-26 15:44     ` Stefan Monnier
2015-01-27  6:08       ` Thierry Volpiatto
2015-01-26 16:34     ` Artur Malabarba
2015-01-28  7:30   ` Thierry Volpiatto
2015-01-28  8:55     ` Thierry Volpiatto
2015-01-28 12:42       ` Thierry Volpiatto
2015-01-28 13:17         ` Artur Malabarba
2015-01-28 14:32           ` Thierry Volpiatto
2015-01-28 13:40         ` Dmitry Gutov
2015-01-28 10:47     ` Artur Malabarba
2015-01-28 11:58       ` Thierry Volpiatto
2015-01-28 19:33       ` Stefan Monnier
2015-01-28 19:50         ` Ivan Shmakov
2015-01-28 20:12           ` Artur Malabarba
2015-01-28 22:20           ` Stefan Monnier
2015-01-29  5:31         ` Thierry Volpiatto
2015-01-29  7:22           ` Thierry Volpiatto
2015-01-30  5:38   ` Thierry Volpiatto
2015-01-30 16:43     ` Artur Malabarba
2015-01-30 17:13       ` Thierry Volpiatto
2015-01-31  6:01       ` Thierry Volpiatto
2015-01-31 10:58         ` Artur Malabarba
2015-01-31 20:26         ` Stefan Monnier
     [not found]           ` <874mr67gjb.fsf@gmail.com>
     [not found]             ` <jwvvbjmnun4.fsf-monnier+emacs@gnu.org>
     [not found]               ` <87oapervqv.fsf@gmail.com>
     [not found]                 ` <jwvk302nnmd.fsf-monnier+emacs@gnu.org>
     [not found]                   ` <877fw2kp1y.fsf@gmail.com>
     [not found]                     ` <jwvioflbrlg.fsf-monnier+emacs@gnu.org>
     [not found]                       ` <87d25tps2q.fsf@gmail.com>
     [not found]                         ` <jwvy4oggva5.fsf-monnier+emacs@gnu.org>
2015-02-02 20:35                           ` Thierry Volpiatto
2015-02-02 21:37                             ` Artur Malabarba
2015-02-03  4:53                               ` Thierry Volpiatto
2015-02-03  5:13                                 ` Stefan Monnier
2015-02-03 10:04                                 ` Artur Malabarba
2015-02-03 14:06                                 ` Artur Malabarba
2015-02-03  5:45                               ` Thierry Volpiatto
2015-02-03 10:05                                 ` Artur Malabarba
2015-02-03 10:18                                   ` Thierry Volpiatto
2015-02-03 11:39                             ` Artur Malabarba
2015-02-02 21:19                           ` Thierry Volpiatto
2015-02-02 21:22                             ` Dmitry Gutov
2015-02-03 11:39                               ` Artur Malabarba
2015-02-03 11:44                                 ` Dmitry Gutov
2015-01-31  6:51       ` Thierry Volpiatto
2015-01-31 20:30         ` Stefan Monnier
2015-01-31 22:10           ` Thierry Volpiatto
2015-01-31 23:26           ` Artur Malabarba
2015-02-01  6:29             ` Thierry Volpiatto
2015-02-01  7:02             ` Thierry Volpiatto
2015-02-01 15:55             ` Thierry Volpiatto
2015-02-01 23:47               ` Artur Malabarba
2015-02-02 12:00           ` Artur Malabarba
2015-02-02 13:14             ` Thierry Volpiatto
2015-02-02 14:14               ` Thierry Volpiatto
2015-02-02 14:56                 ` Artur Malabarba
2015-02-02 15:19                   ` Thierry Volpiatto
2015-02-02 15:33                     ` Thierry Volpiatto
2015-02-02 15:50                       ` Artur Malabarba
2015-02-02 16:07                         ` Thierry Volpiatto
2015-02-02 21:23                         ` Thierry Volpiatto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y4oqg8tg.fsf@gmail.com \
    --to=thierry.volpiatto@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.