Subject: bug#14967: 24.3.50; package-delete deletes by trashing?

From: Alex <[email-masked]>
Date: Sun, 11 Jun 2017 21:26:20 -0600

[email-masked] writes:

> severity 14967 wishlist
> quit
>
> Alex <[email-masked]> writes:
>
>> Stefan Monnier <[email-masked]> writes:
>>
>>>> Well, obviously I consider this behavior a bug.  Trash is no place for
>>>> deleted packages.  I mean, does apt-get remove use the Trash?!
>>>
>>> I think the reasoning goes as follows:
>>> Emacs uses "trash" when deleting a file upon the user's request (as
>>> opposed to things like temp files used internally).
>>
>> Could there perhaps be a separate configuration option for deleting
>> packages versus trashing them? I usually like Emacs using the trash, but
>> I don't see a reason why packages should go there myself.
>
> Seems reasonable.

Here's a patch for it.

>From cf3039f10846155fde224a1f6c249799ab7cf41d Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <[email-masked]>
Date: Sun, 11 Jun 2017 21:12:24 -0600
Subject: [PATCH] Make package-delete conditionally not use the trash

Some users would like to trash other files, but not old package
files (Bug#14967).

* lisp/emacs-lisp/package.el: Add `package-trash-old-packages'.
* etc/NEWS: Document it.
---
 etc/NEWS                   | 3 +++
 lisp/emacs-lisp/package.el | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 7972511f7a..fa1e5c1312 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -743,6 +743,9 @@ header's value.
 where the GnuPG home directory (used for signature verification) is
 located and whether GnuPG's option "--homedir" is used or not.
 
+*** The new variable 'package-trash-old-packages' has been added to
+control whether or not 'package-delete' trashes old packages files.
+
 ** Tramp
 
 +++
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index bebfd18d7a..5173a32e33 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2071,6 +2071,11 @@ package--newest-p
   (equal (cadr (assq (package-desc-name pkg) package-alist))
          pkg))
 
+(defvar package-trash-old-packages t
+  "If non-nil, `package-delete' may trash packages.
+`delete-by-moving-to-trash' must be non-nil for this variable to
+have an effect.")
+
 (defun package-delete (pkg-desc &optional force nosave)
   "Delete package PKG-DESC.
 
@@ -2127,7 +2132,7 @@ package-delete
                   (package-desc-name pkg-used-elsewhere-by)))
           (t
            (add-hook 'post-command-hook #'package-menu--post-refresh)
-           (delete-directory dir t t)
+           (delete-directory dir t package-trash-old-packages)
            ;; Remove NAME-VERSION.signed and NAME-readme.txt files.
            (dolist (suffix '(".signed" "readme.txt"))
              (let* ((version (package-version-join (package-desc-version pkg-desc)))
-- 
2.11.0