GNU bug report logs - #79277
31.0.50; Dired errors when trying to overwrite broken symlink

Previous Next

Package: emacs;

Reported by: Michael Heerdegen <michael_heerdegen <at> web.de>

Date: Wed, 20 Aug 2025 09:25:02 UTC

Severity: normal

Found in version 31.0.50

To reply to this bug, email your comments to 79277 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#79277; Package emacs. (Wed, 20 Aug 2025 09:25:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michael Heerdegen <michael_heerdegen <at> web.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 20 Aug 2025 09:25:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; Dired errors when trying to overwrite broken symlink
Date: Wed, 20 Aug 2025 11:25:28 +0200
Hello,

In dired call S or Y and specify a file name that names a broken
symlink.  This just raises a 'file-already-exists' error.

Of course we want the user to be asked whether the file should be
overwritten, as in all similar cases.

The reason for the different handling is that this test in
`dired-create-files':

   (let* ((overwrite (file-exists-p to)) ...

is wrong because it doesn't handle symlinks as intended.  We
want the test to succeed.  If TO is a symlink it is irrelevant
whether the link target exists.  The fix is obvious.

But since this case is a recurring source of confusion and coding errors
I wonder if we want to introduce a new test function (at least to dired)
that would handle this case directly.  Something named
`dired-file-name-exists-p' maybe?  It would not follow symlinks but just
tell whether a specified file name is already in use.


TIA,

Michael.


In GNU Emacs 31.0.50 (build 10, x86_64-pc-linux-gnu, cairo version
 1.16.0) of 2025-08-19 built on drachen
Repository revision: ced457fd86f90b035e1f40186f4ff957f82e715e
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --with-x-toolkit=no --with-native-compilation=no'





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79277; Package emacs. (Sun, 24 Aug 2025 09:59:01 GMT) Full text and rfc822 format available.

Message #8 received at 79277 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 79277 <at> debbugs.gnu.org
Subject: Re: bug#79277: 31.0.50;
 Dired errors when trying to overwrite broken symlink
Date: Sun, 24 Aug 2025 12:58:33 +0300
> Date: Wed, 20 Aug 2025 11:25:28 +0200
> From:  Michael Heerdegen via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> In dired call S or Y and specify a file name that names a broken
> symlink.  This just raises a 'file-already-exists' error.
> 
> Of course we want the user to be asked whether the file should be
> overwritten, as in all similar cases.
> 
> The reason for the different handling is that this test in
> `dired-create-files':
> 
>    (let* ((overwrite (file-exists-p to)) ...
> 
> is wrong because it doesn't handle symlinks as intended.  We
> want the test to succeed.  If TO is a symlink it is irrelevant
> whether the link target exists.  The fix is obvious.

What kind of fix did you have in mind?

> But since this case is a recurring source of confusion and coding errors
> I wonder if we want to introduce a new test function (at least to dired)
> that would handle this case directly.

Can you point to other places where this issue arises?

> Something named `dired-file-name-exists-p' maybe?  It would not
> follow symlinks but just tell whether a specified file name is
> already in use.

If it turns out there are enough users for this, it sounds to me like
a useful utility on its own right, not specific to Dired, suitable to
files.el or maybe files-x.el.  (If we do that, we should update the
ELisp manual as well.)

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79277; Package emacs. (Sat, 13 Sep 2025 06:24:03 GMT) Full text and rfc822 format available.

Message #11 received at 79277 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 79277 <at> debbugs.gnu.org
Subject: Re: bug#79277: 31.0.50; Dired errors when trying to overwrite
 broken symlink
Date: Sat, 13 Sep 2025 08:25:07 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

> > Date: Wed, 20 Aug 2025 11:25:28 +0200
> > From:  Michael Heerdegen via "Bug reports for GNU Emacs,
> >  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> > 
> > In dired call S or Y and specify a file name that names a broken
> > symlink.  This just raises a 'file-already-exists' error.
> > 
> > Of course we want the user to be asked whether the file should be
> > overwritten, as in all similar cases.
> > 
> > The reason for the different handling is that this test in
> > `dired-create-files':
> > 
> >    (let* ((overwrite (file-exists-p to)) ...
> > 
> > is wrong because it doesn't handle symlinks as intended.  We
> > want the test to succeed.  If TO is a symlink it is irrelevant
> > whether the link target exists.  The fix is obvious.
>
> What kind of fix did you have in mind?

Using (or (file-symlink-p to) (file-exists-p to)) would be correct -
right?

> > But since this case is a recurring source of confusion and coding errors
> > I wonder if we want to introduce a new test function (at least to dired)
> > that would handle this case directly.
>
> Can you point to other places where this issue arises?

It seems it doesn't occur that often.  Very few occurrences are in
Tramp.  2 or so.

> > Something named `dired-file-name-exists-p' maybe?  It would not
> > follow symlinks but just tell whether a specified file name is
> > already in use.
>
> If it turns out there are enough users for this, it sounds to me like
> a useful utility on its own right, not specific to Dired, suitable to
> files.el or maybe files-x.el.  (If we do that, we should update the
> ELisp manual as well.)

If "users" means Emacs own Elisp sources than there are probably not
enough users.  So I would be fine with just fixing the issue.


Thanks,

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79277; Package emacs. (Sat, 13 Sep 2025 07:22:02 GMT) Full text and rfc822 format available.

Message #14 received at 79277 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 79277 <at> debbugs.gnu.org
Subject: Re: bug#79277: 31.0.50; Dired errors when trying to overwrite
 broken symlink
Date: Sat, 13 Sep 2025 10:21:29 +0300
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: 79277 <at> debbugs.gnu.org
> Date: Sat, 13 Sep 2025 08:25:07 +0200
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > > Date: Wed, 20 Aug 2025 11:25:28 +0200
> > > From:  Michael Heerdegen via "Bug reports for GNU Emacs,
> > >  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> > > 
> > > In dired call S or Y and specify a file name that names a broken
> > > symlink.  This just raises a 'file-already-exists' error.
> > > 
> > > Of course we want the user to be asked whether the file should be
> > > overwritten, as in all similar cases.
> > > 
> > > The reason for the different handling is that this test in
> > > `dired-create-files':
> > > 
> > >    (let* ((overwrite (file-exists-p to)) ...
> > > 
> > > is wrong because it doesn't handle symlinks as intended.  We
> > > want the test to succeed.  If TO is a symlink it is irrelevant
> > > whether the link target exists.  The fix is obvious.
> >
> > What kind of fix did you have in mind?
> 
> Using (or (file-symlink-p to) (file-exists-p to)) would be correct -
> right?

Feel free to suggest a patch along these lines.

> > > But since this case is a recurring source of confusion and coding errors
> > > I wonder if we want to introduce a new test function (at least to dired)
> > > that would handle this case directly.
> >
> > Can you point to other places where this issue arises?
> 
> It seems it doesn't occur that often.  Very few occurrences are in
> Tramp.  2 or so.
> 
> > > Something named `dired-file-name-exists-p' maybe?  It would not
> > > follow symlinks but just tell whether a specified file name is
> > > already in use.
> >
> > If it turns out there are enough users for this, it sounds to me like
> > a useful utility on its own right, not specific to Dired, suitable to
> > files.el or maybe files-x.el.  (If we do that, we should update the
> > ELisp manual as well.)
> 
> If "users" means Emacs own Elisp sources than there are probably not
> enough users.  So I would be fine with just fixing the issue.

Agreed, thanks.




This bug report was last modified 55 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.