Subject: bug#58721: 28.2; dired with delete-by-moving-to-trash can't trash directory twice

From: Eli Zaretskii <[email-masked]>
Date: Thu, 27 Oct 2022 21:20:32 +0300

> From: Gustavo Barros <[email-masked]>
> Date: Thu, 27 Oct 2022 14:51:39 -0300
> Cc: [email-masked]
> 
> I clone the repo, and move it to trash with (move-file-to-trash
> "/path/to/org-mode").
> 
> Now "~/.local/share/Trash/files" contains "org-mode", with proper
> contents, as expected.
> 
> I clone again and move to trash again with (move-file-to-trash
> "/path/to/org-mode"). Now it fails with "(file-already-exists "File
> exists" "/home/<username>/.local/share/Trash/files/org-mode7AV...")",
> and "~/.local/share/Trash/files" contains:
> 
>     org-mode
>     org-mode7AVOuq
> 
> Where "org-mode7AVOuq" is empty. And "org-mode", with contents, is
> still in "/path/to/org-mode".

We need to understand when was org-mode7AVOuq created, and why does
Emacs tries to create it again.  AFAIU from your description,
org-mode7AVOuq was not created by the first move to trash, so why does
only the second move to trash cause the error?