Subject: Re: bug#6960: mv refuses to move a symlink over a hard link to the same file

From: Davide Brini <[email-masked]>
Date: Tue, 31 Aug 2010 23:48:56 +0100

On Tue, 31 Aug 2010 17:21:08 -0400
Matt McCutchen <[email-masked]> wrote:

> If mv is asked to move a symlink over a hard link to the same file, it
> fails with the message, "A and B are the same file".  There is no reason
> why it should complain rather than perform the move.  Example:
> 
> $ ~/coreutils/coreutils.usr/bin/mv --version
> mv (GNU coreutils) 8.5.143-77702
> Copyright (C) 2010 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later
> <http://gnu.org/licenses/gpl.html>. This is free software: you are free
> to change and redistribute it. There is NO WARRANTY, to the extent
> permitted by law.
> 
> Written by Mike Parker, David MacKenzie, and Jim Meyering.
> $ touch New_York
> $ ln New_York localtime
> $ ln -s New_York localtime.new
> $ ls -l
> total 0
> -rw------- 2 matt matt 0 2010-08-31 17:10 New_York
> -rw------- 2 matt matt 0 2010-08-31 17:10 localtime
> lrwxrwxrwx 1 matt matt 8 2010-08-31 17:11 localtime.new -> New_York
> $ ~/coreutils/coreutils.usr/bin/mv localtime.new localtime
> /home/matt/coreutils/coreutils.usr/bin/mv: `localtime.new' and
> `localtime' are the same file

A simpler example is something like

$ touch New_York
$ ln -s New_York New_York.sym
$ mv New_York.sym New_York 
mv: `New_York.sym' and `New_York' are the same file

I think the reason is that when the source is a symbolic link, mv operates
on the symlink itself, not the file it points to. So, it can't rename the
symlink, because if successful that would imply having two entries named
"New_York" in the same directory. If this is really the reason for the
error, the error message could probably be improved.

-- 
D.