Bug 17847

Summary: mv symbolic link cross partition fails
Product: Base System Reporter: Jin Guojun <jin>
Component: binAssignee: dwmalone
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Jin Guojun 2000-04-07 19:00:01 UTC
	This is supposed to be for "mv slink another_partition"

[125] solaris: cd /tmp;	ln -s x y
[126] solaris: ll
lrwxrwxrwx   1 jin             1 Apr  7 10:32 y -> x
[127] solaris: mv y ~
[128] solaris: ll ~/y
lrwxrwxrwx   1 jin             1 Apr  7 10:32 /home/users/jin/y -> x

	This is what happened on FreeBSD mv:

[111] FreeBSD: cd /tmp
[112] FreeBSD: mkdir test
[113] FreeBSD: ln -s x y
[114] FreeBSD: mv y test
[115] FreeBSD: ll test
total 2
drwxr-xr-x  2 jin   wheel  512 Apr  7 10:34 ./
drwxrwxrwt  4 root  wheel  512 Apr  7 10:34 ../
lrwxr-xr-x  1 jin   wheel    1 Apr  7 10:34 y@ -> x	# ok for local mv

[116] FreeBSD: cd test
[117] FreeBSD: mv y ~
mv: y: No such file or directory			# failed HERE
[118] FreeBSD: echo abc > x
[119] FreeBSD: ll
total 3
drwxr-xr-x  2 jin   wheel  512 Apr  7 10:48 ./
drwxrwxrwt  4 root  wheel  512 Apr  7 10:34 ../
-rw-r--r--  1 jin   wheel    4 Apr  7 10:48 x
lrwxr-xr-x  1 jin   wheel    1 Apr  7 10:34 y@ -> x
[120] FreeBSD: mv y ~			# incorrect for crossing partition
[121] FreeBSD: ll ~/y
-rw-r--r--  1 jin  wheel  4 Apr  7 10:48 /home/users/jin/y
[122] FreeBSD: cat ~/y
abc
[123] FreeBSD: ll
total 3
drwxr-xr-x  2 jin   wheel  512 Apr  7 10:49 ./
drwxrwxrwt  4 root  wheel  512 Apr  7 10:34 ../
-rw-r--r--  1 jin   wheel    4 Apr  7 10:48 x

Fix: 

If every one agree this incorrect, I can trace down the code to
	find a patch.
How-To-Repeat: 
	Just repeat above operatoins within the same/different partitions.
Comment 1 dwmalone 2000-04-07 20:28:07 UTC
> 	If every one agree this incorrect, I can trace down the code to
> 	find a patch.

This sounds like a bug, as it doesn't do the same thing as mving
a symlink on a local partition would. If the file the symlink points
to is a regular file you'll end up getting a copy of that instead
of the symlink.

Digital Unix and Linux also do the same "correct" thing as solaris.

It looks like mv has a stat, which should be an lstat. The included
patch seems to fix it.

BTW - for some strange reason your PR seems to be marked as
confidential on the web site.

	David.

--- mv.c	Fri Apr  7 20:19:19 2000
+++ mv.c.orig	Fri Apr  7 20:19:45 2000
@@ -221,7 +221,7 @@
 	 * it's a regular file, do the copy internally; otherwise, use
 	 * cp and rm.
 	 */
-	if (lstat(from, &sb)) {
+	if (stat(from, &sb)) {
 		warn("%s", from);
 		return (1);
 	}
Comment 2 Jin Guojun 2000-04-07 21:43:02 UTC
Yes, following patch fixed the problem.
Shall we apply the patch and close the case?

Thanks,

	-Jin

--------- original message ------
>       If every one agree this incorrect, I can trace down the code to
>       find a patch.

This sounds like a bug, as it doesn't do the same thing as mving
a symlink on a local partition would. If the file the symlink points
to is a regular file you'll end up getting a copy of that instead
of the symlink.

Digital Unix and Linux also do the same "correct" thing as solaris.

It looks like mv has a stat, which should be an lstat. The included
patch seems to fix it.

BTW - for some strange reason your PR seems to be marked as
confidential on the web site.

        David.

--- mv.c	Fri Apr  7 20:19:19 2000
+++ mv.c.orig	Fri Apr  7 20:19:45 2000
@@ -221,7 +221,7 @@
 	 * it's a regular file, do the copy internally; otherwise, use
 	 * cp and rm.
 	 */
-	if (lstat(from, &sb)) {
+	if (stat(from, &sb)) {
 		warn("%s", from);
 		return (1);
 	}
Comment 3 dwmalone freebsd_committer freebsd_triage 2000-07-11 12:44:31 UTC
Responsible Changed
From-To: freebsd-bugs->dwmalone

I'm interested in this one.
Comment 4 dwmalone freebsd_committer freebsd_triage 2000-07-14 20:26:23 UTC
State Changed
From-To: open->closed

Fix has been committed in RELENG_{3,4} and HEAD.