Debian Bug report logs - #654666
mv -f refuses to replace a file with a symlink to the same inode

version graph

Package: coreutils; Maintainer for coreutils is Michael Stone <[email protected]>; Source for coreutils is src:coreutils (PTS, buildd, popcon).

Reported by: Jonathan Nieder <[email protected]>

Date: Thu, 5 Jan 2012 00:36:05 UTC

Severity: important

Tags: fixed-upstream, upstream

Found in versions coreutils/8.13-3, coreutils/8.5-1

Fixed in version 9.7-1

Done: Michael Stone <[email protected]>

Forwarded to http://debbugs.gnu.org/6960

Reply or subscribe to this bug.

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


Report forwarded to [email protected], Michael Stone <[email protected]>:
Bug#654666; Package coreutils. (Thu, 05 Jan 2012 00:36:08 GMT) (full text, mbox, link).


Acknowledgement sent to Jonathan Nieder <[email protected]>:
New Bug report received and forwarded. Copy sent to Michael Stone <[email protected]>. (Thu, 05 Jan 2012 00:36:08 GMT) (full text, mbox, link).


Message #5 received at [email protected] (full text, mbox, reply):

From: Jonathan Nieder <[email protected]>
To: [email protected]
Subject: mv -f refuses to replace a file with a symlink to the same inode
Date: Wed, 4 Jan 2012 18:34:12 -0600
Package: coreutils
Version: 8.5-1
Tags: upstream
Forwarded: http://debbugs.gnu.org/6960

Hi,

I have a hard link that I want to replace with a symlink without
disturbing concurrent tasks:

	echo "some data" >file
	ln file link
	ln -s file link.tmp
	mv -f link.tmp link

I would expect that to succeed.  Instead:

	$ mv -f link.tmp link
	mv: `link.tmp' and `link' are the same file

POSIX is somewhat unclear about this situation:

	If the source_file operand and destination path name the same
	existing file, then the destination path shall not be removed,
	and [...]

The crux is what it means to "name the same existing file".  As
explained at [1], I believe that passage is not intended to apply to a
symlink and hard link to the same file, but it's hard to be sure.

Aside from POSIX, there are other reasons to want to be able to do
this easily, but that's already well covered in the upstream report.
See http://bugs.debian.org/654596 for context.

Nothing particularly urgent about this; just filing so it doesn't get
forgotten.

Thanks for keeping coreutils working well.
Jonathan

[1] http://austingroupbugs.net/view.php?id=534

If this passage applies to cases where src is a symlink to the same
inode as dst, then a POSIX-compliant mv implementation could act as
though I had written "rm -f link.tmp" instead of "mv ...", which seems
a little insane.  Hopefully the Austin group will clarify it soon.




Bug Marked as found in versions coreutils/8.13-3. Request was from Jonathan Nieder <[email protected]> to [email protected]. (Sun, 29 Jan 2012 02:24:02 GMT) (full text, mbox, link).


Severity set to 'important' from 'normal' Request was from Jonathan Nieder <[email protected]> to [email protected]. (Sun, 29 Jan 2012 02:24:03 GMT) (full text, mbox, link).


Information forwarded to [email protected], Michael Stone <[email protected]>:
Bug#654666; Package coreutils. (Wed, 08 Feb 2012 01:00:03 GMT) (full text, mbox, link).


Acknowledgement sent to Jonathan Nieder <[email protected]>:
Extra info received and forwarded to list. Copy sent to Michael Stone <[email protected]>. (Wed, 08 Feb 2012 01:00:04 GMT) (full text, mbox, link).


Message #14 received at [email protected] (full text, mbox, reply):

From: Jonathan Nieder <[email protected]>
To: [email protected]
Subject: Re: mv -f refuses to replace a file with a symlink to the same inode
Date: Tue, 7 Feb 2012 18:55:48 -0600
Hi,

Jonathan Nieder wrote:

>	echo "some data" >file
>	ln file link
>	ln -s file link.tmp
>	mv -f link.tmp link
>
> I would expect that to succeed.

There's a patch upstream (d1b0155d, "mv: allow moving symlink onto
same-inode dest with >= 2 hard links") that treats the symptoms.
Unfortunately that patch does not solve the full problem: coreutils mv
is still too clever for its own good and is still not compliant with
the (now clarified) POSIX requirements.

Not sure what to do with this bug report.  Maybe it would be worth
tracking "allow replacing a hard link by a symlink" and "use lstat,
not stat, for same-file check, as required by POSIX" separately.

Thanks,
Jonathan




Added tag(s) fixed-upstream. Request was from [email protected] to [email protected]. (Mon, 14 Jan 2019 17:42:30 GMT) (full text, mbox, link).


Reply sent to Michael Stone <[email protected]>:
You have taken responsibility. (Sun, 20 Apr 2025 17:12:01 GMT) (full text, mbox, link).


Notification sent to Jonathan Nieder <[email protected]>:
Bug acknowledged by developer. (Sun, 20 Apr 2025 17:12:01 GMT) (full text, mbox, link).


Message #21 received at [email protected] (full text, mbox, reply):

From: Michael Stone <[email protected]>
To: [email protected]
Subject: Re: mv -f refuses to replace a file with a symlink to the same inode
Date: Sun, 20 Apr 2025 13:08:43 -0400
Version: 9.7-1



Send a report that this bug log contains spam.


Debian bug tracking system administrator <[email protected]>. Last modified: Tue May 13 08:50:17 2025; Machine Name: buxtehude

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU General Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.