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

From: Gustavo Barros <[email-masked]>
Date: Thu, 27 Oct 2022 16:07:14 -0300

On Thu, 27 Oct 2022 at 15:41, Gustavo Barros <[email-masked]> wrote:

> > [...] so why does
> > only the second move to trash cause the error?
>
> As far as I can tell, the existence of
> "~/.local/share/Trash/files/org-mode" triggers it. I'd presume that
> its existence takes the execution path to some code branch (the one
> which tries to uniquify the file name/calls make-temp-file) which
> tries to somehow create the directory twice.
>
> But there's more to it. In the original report I explained why I ended
> up "cloning the org repo" for this. Indeed, when creating the
> reproduction recipe, I've tried first to create a simple empty file
> with `touch' and a simple empty dir with `mkdir', but those did not
> trigger the error. This is utterly mysterious to me. Perhaps something
> like "size induced delay with some asynchronous process"? But that's
> just a (very) wild guess. Truth is, I'm at a loss. And I did go
> through the rabbit role to some extent, which resulted in that other
> report about `move-file-to-trash', but I could not understand what's
> going on here.

I just had an idea here to test the "delay" hypothesis, and it paid off.

All of my tests so far were being done from one of two places, the
"/tmp/" dir, or the place in my user files where I keep Emacs cloned
libraries. And they share a characteristic in my system, neither is in
the same filesystem as "~/.local/share/Trash/". "/tmp/" is a tmpfs
mount, and my personal files are in a separate encrypted partition.

Hence, what I did now, was to follow the recipe, but instead cloning
to "~", which is in the same partition as the Trash. And, guess what?
The error does not occur!

So it seems indeed a delay is at play. And that this one is related to
bug#58781, after all. A "fix" there would "fix" here too. But by luck,
because it would make the move "quick enough". However, the behavior
does suggest there's really some double attempt to create the
directory somewhere in the code.