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

From: Gustavo Barros <[email-masked]>
Date: Fri, 28 Oct 2022 09:35:45 -0300

On Fri, 28 Oct 2022 at 08:44, Eli Zaretskii <[email-masked]> wrote:

> I don't have the necessary configuration here to try reproducing.  You
> said it doesn't happen when moving to trash just a small directory, so
> it's quite clear that something specific to your system is at work here.

This is no longer about `move-file-to-trash', but about `rename-file'
third argument. So you don't need a freedesktop.org Trash to
reproduce. Of course, it doesn't mean you can reproduce it, since
there might still be something else which is system specific.

I've tried to isolate things from the Trash issue, and I could
reproduce the problem with the following steps.

I grabbed two USB sticks, formatted both of them with EXT4 (I used
Mint's "USB Stick formatter" tool, I suppose it is pretty standard in
what it does), labeled each "orig" and "dest". Mounted both.

In the terminal, I did:

$ cd /path/to/orig
$ mkdir barbaz
$ cd barbaz
$ dd if=/dev/zero of=zero.file bs=1024 count=204800
$ cd /path/to/dest
$ mkdir barbaz-foobar

I started "emacs -Q", and issued:

(rename-file "/path/to/orig/barbaz" "/path/to/dest/barbaz-foobar" t)

And got "(file-already-exists "File exists" "/path/to/dest/barbaz-foobar")"

> Try figuring out why the make-directory call fails.  What is the name
> of the directory that fails the call, and why?

I can try further, but I did try quite hard already.
And I don't think this has anything to do with particular names, I
used foo bar stuff above on purpose, and they are our quintessential
"arbitrary".

> Here are some questions for you to try to answer:
>
>   . Does this happen only with moves across filesystems?

Formally, what I tested is that when I tried the same recipe of the
original report, but with the "org-mode" directory I was trying to
delete/trash located in the same partition as the Trash, the error did
not occur.

So, the answer is that, as far as I can tell "yes", but the reasoning
is based on small sample inference. "Educated" perhaps, but I can't
make a rule out of it.

>   . Would any target filesystem do, or just some special kind(s)/

In the example above I used standard EXT4 ones. I'd say this should
work on them, but I haven't tried other ones. Would you like me to
test anything specific in this regard?

>   . What is the difference between the first move and the subsequent
>     moves that triggers the error?

I think this question only applies to `move-file-to-trash', we don't
need "two moves" anymore with the example boiled down to
`rename-file'. We know `move-file-to-trash' does create an empty dir
there, and this only happens when a file of the same name exists
(which required the "first move"), but it also sets the `overwrite'
flag, the problem is that the flag fails.

Thank *you*.