Merge with FreeBSD (RELENG_4) src/bin/mv/mv.c, revision 1.24.2.6:
authorChris Pressey <cpressey@dragonflybsd.org>
Mon, 3 May 2004 18:54:37 +0000 (18:54 +0000)
committerChris Pressey <cpressey@dragonflybsd.org>
Mon, 3 May 2004 18:54:37 +0000 (18:54 +0000)
Fix a bug that would not allow a symbolic link to be moved if its
destination was a mount point (details in FreeBSD PR bin/64430).

Reviewed-by: hmp
bin/mv/mv.c

index 977d13e..eb80a1a 100644 (file)
@@ -35,8 +35,8 @@
  *
  * @(#) Copyright (c) 1989, 1993, 1994 The Regents of the University of California.  All rights reserved.
  * @(#)mv.c    8.2 (Berkeley) 4/2/94
- * $FreeBSD: src/bin/mv/mv.c,v 1.24.2.5 2002/08/19 00:26:41 johan Exp $
- * $DragonFly: src/bin/mv/mv.c,v 1.4 2003/09/28 14:39:14 hmp Exp $
+ * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/bin/mv/mv.c,v 1.24.2.6 2004/03/24 08:34:36 pjd Exp $
+ * $DragonFly: src/bin/mv/mv.c,v 1.5 2004/05/03 18:54:37 cpressey Exp $
  */
 
 #include <sys/param.h>
@@ -200,14 +200,25 @@ do_move(char *from, char *to)
                struct statfs sfs;
                char path[PATH_MAX];
 
-               /* Can't mv(1) a mount point. */
-               if (realpath(from, path) == NULL) {
-                       warnx("cannot resolve %s: %s", from, path);
+               /*
+                * If the source is a symbolic link and is on another
+                * filesystem, it can be recreated at the destination.
+                */
+               if (lstat(from, &sb) == -1) {
+                       warn("%s", from);
                        return (1);
                }
-               if (!statfs(path, &sfs) && !strcmp(path, sfs.f_mntonname)) {
-                       warnx("cannot rename a mount point");
-                       return (1);
+               if (!S_ISLNK(sb.st_mode)) {
+                       /* Can't mv(1) a mount point. */
+                       if (realpath(from, path) == NULL) {
+                               warnx("cannot resolve %s: %s", from, path);
+                               return (1);
+                       }
+                       if (!statfs(path, &sfs) &&
+                           !strcmp(path, sfs.f_mntonname)) {
+                               warnx("cannot rename a mount point");
+                               return (1);
+                       }
                }
        } else {
                warn("rename %s to %s", from, to);