Subject: bug#76678: 31.0.50; Can't trash broken links

From: Michael Albinus <[email-masked]>
Date: Tue, 04 Mar 2025 08:42:13 +0100

Stefan Kangas <[email-masked]> writes:

Hi Stefan,

>> 3. Create a file and symlink it to /usr/local/bin.
>> 4. Delete the file, but not the symlink.
>> 5. Go to /usr/local/bin using find-file command.
>> 6. Execute 'tramp-revert-buffer-with-sudo'.
>> 7. Execute 'dired-do-delete' on the broken symlink.
>
> Michael, could you please take a look at this?

I'm working already on this for two days. It is simple to reproduce, and
I have already extended tramp-tests.el for this case. This helps me also
debugging.

However, the fix isn't easy. Finally, the problem is a subtle behavior
of file-exists-p. If it is called with a symlinked file, valid target,
it returns t. If the target doesn't exist, it returns nil.

The Tramp implementation returns always t, whether the target exists or
not. Wrong.

I've fixed tramp-sh-handle-file-exists-p accordingly. But now, since
file-exists-p is used everywhere in Tramp, I must test everything.
Sometimes the changed implementation results in new errors, and I must
change code to '(or (file-exists-p filename) (file-symlinkp filename))'
at places, which have used a simple '(file-exists-p filename)' before.

This will take time.

Best regards, Michael.