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

From: Alex <[email-masked]>
Date: Mon, 12 Jun 2017 13:37:46 -0600

Eli Zaretskii <[email-masked]> writes:

>> +(defvar package-trash-old-packages t
>> +  "If non-nil, `package-delete' may trash packages.
>
> Why "may"?

Since after this patch, `package-delete' may trash packages, or may not,
depending on the value of `delete-by-moving-to-trash'.

>> +`delete-by-moving-to-trash' must be non-nil for this variable to
>> +have an effect.")
>
> I think it would be better to make this defcustom.

Right, I forgot to do that. I updated and attached a new patch.

>From ee33b113826efb6130dfe2d9c568b8e4ddc80eb2 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                   | 4 ++++
 lisp/emacs-lisp/package.el | 9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 7972511f7a..ee99d114a7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -743,6 +743,10 @@ 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. The default behaviour is to trash old packages.
+
 ** Tramp
 
 +++
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index bebfd18d7a..c92ce19e6c 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -368,6 +368,13 @@ package-menu-async
   :type 'boolean
   :version "25.1")
 
+(defcustom 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."
+  :type 'boolean
+  :version "26.1")
+
 
 ;;; `package-desc' object definition
 ;; This is the struct used internally to represent packages.
@@ -2127,7 +2134,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