bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mv silently does nothing for hard links


From: Jim Meyering
Subject: Re: mv silently does nothing for hard links
Date: Tue, 08 Apr 2003 15:18:59 +0200

Paul Eggert <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>
>> Here's a patch that solves the problem at zero-to-negligible cost.
>
> You mentioned in
> <http://www.opengroup.org/sophocles/show_mail.tpl?source=L&listname=austin-group-l&id=5156>
> that NetBSD rename(A,B) removes A if A and B are hard links but are
> distinct directory entries, but from code inspection it appears that
> copy_internal will report an error in that case.  Surely it shouldn't

Hi Paul,

The UNLINK_SRC-prompted unlink always happens before
any attempt to rename, so an unlink failure should be diagnosed.
I've just confirmed that the code now works as I'd expect on NetBSD 1.6.
Am I missing something?

> report an error, as it's not the user's fault that NetBSD behaves the
> way that the POSIX authors intended (as opposed to what they actually
> wrote down :-).

> Also, I'm not sure I follow the code completely, but shouldn't hard
> links to symbolic links be handled the same way as hard links to
> regular files?  If rename(A,B) does nothing when A and B are hard
> links to the same symbolic link, then that situation also needs to be
> protected against.

rename does have the same problem with hard links to the same symlink,
but that is already handled by mv from coreutils-5.0, probably by
this code:

      /* If both the source and destination files are symlinks (and we'll
         know this here IFF preserving symlinks (aka xstat == lstat),
         then it's ok -- as long as they are distinct.  */
      if (S_ISLNK (src_sb->st_mode) && S_ISLNK (dst_sb->st_mode))
        return ! same_name (src_path, dst_path);

For example, on a Linux/ext3 system:

  $ touch k; ln -s k s1; ln s1 s2
  $ ls -go -i
  total 0
    16459 -rw-r--r--    1        0 Apr  8 15:06 k
    16460 lrwxrwxrwx    2        1 Apr  8 15:06 s1 -> k
    16460 lrwxrwxrwx    2        1 Apr  8 15:06 s2 -> k
  $ perl -e ' rename "s1", "s2" or die "$!"'
  $ ls -go -i
  total 0
    16459 -rw-r--r--    1        0 Apr  8 15:06 k
    16460 lrwxrwxrwx    2        1 Apr  8 15:06 s1 -> k
    16460 lrwxrwxrwx    2        1 Apr  8 15:06 s2 -> k
  $ mv s1 s2
  $ ls -go -i
  total 0
    16459 -rw-r--r--    1        0 Apr  8 15:06 k
    16460 lrwxrwxrwx    1        1 Apr  8 15:06 s2 -> k

Jim




reply via email to

[Prev in Thread] Current Thread [Next in Thread]