Subject: bug#47960: 28.0.50; delete-by-moving-to-trash fails on directories?

From: Gregory Heytings <[email-masked]>
Date: Fri, 23 Apr 2021 20:39:20 +0000

>
> What seems to be the issue is when a deleted entry of the same name 
> already exists.  I emptied my trash and tried the above recipe: the 
> problem would not occur.  But upon immediate retry the problem appeared, 
> presumably because "test" already existed in the trash.
>

Indeed, this path of the code was recently changed (commit a5197e2240), 
and indeed, when a directory with the same name is trashed twice, it 
fails.  Patch attached.

(It can't be applied yet, I'm still waiting for the end of my paperwork.)

From 68dece8c81045aad8c589777a7dc66a7e38e6385 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Fri, 23 Apr 2021 20:32:02 +0000
Subject: [PATCH] Fix bug when moving directories to trash

* lisp/files.el (move-file-to-trash): Pass the correct dir-flag to
make-temp-file so that a directory is created when a directory is
being trashed (Bug#47960).
---
 lisp/files.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/files.el b/lisp/files.el
index 7440c11a21..27282f09fc 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7878,6 +7878,7 @@ move-file-to-trash
 
 	       ;; Make a .trashinfo file.  Use O_EXCL, as per trash-spec 1.0.
 	       (let* ((files-base (file-name-nondirectory fn))
+                      (is-directory (file-directory-p fn))
                       (overwrite nil)
                       info-fn)
                  ;; We're checking further down whether the info file
@@ -7889,7 +7890,8 @@ move-file-to-trash
                          files-base (file-name-nondirectory
                                      (make-temp-file
                                       (expand-file-name
-                                       files-base trash-files-dir)))))
+                                       files-base trash-files-dir)
+                                      is-directory))))
 		 (setq info-fn (expand-file-name
 				(concat files-base ".trashinfo")
 				trash-info-dir))
-- 
2.30.2