🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by David L. Stevens Sat, 25 Oct 1986 18:44
mv with symbolic links fix
#336
Author: David L. Stevens
Date: Sat, 25 Oct 1986 18:44
67 lines
2024 bytes
Index:	/usr/src/bin/mv.c  2.9BSD

Description:
	The distributed mv copies when the source is a symbolic link,
	resulting in 2 instances of the file.
Repeat-By:
	ln -s /etc/passwd /tmp/hose
	mv /tmp/hose /tmp/hosedmore
	ls -l /tmp/hosedmore	(not a link => WRONG)
Fix:
	The fix is to use symlink(), instead of link(), when the source
	is a symbolic link. Diffs follow:

*** OLD mv.c	Sat Oct 25 12:34:16 1986
--- mv.c	Sat Oct 18 23:47:09 1986
***************
*** 97,103
  	int	status;
  	char	buf[MAXN];
  
! 	if (stat(source, &s1) < 0) {
  		fprintf(stderr, "mv: cannot access %s\n", source);
  		return(1);
  	}

--- 97,103 -----
  	int	status;
  	char	buf[MAXN];
  
! 	if (lstat(source, &s1) < 0) {
  		fprintf(stderr, "mv: cannot access %s\n", source);
  		return(1);
  	}
***************
*** 142,148
  			}
  		}
  	}
! 	if (link(source, target) < 0) {
  		i = fork();
  		if (i == -1) {
  			fprintf(stderr, "mv: try again\n");

--- 142,161 -----
  			}
  		}
  	}
! 	if ((s1.st_mode&S_IFMT) == S_IFLNK) {
! 		char lbuf[MAXN];
! 
! 		i = readlink(source, lbuf, sizeof(lbuf));
! 		if (i <= 0) {
! 			fprintf(stderr, "mv: readlink() failed\n");
! 			return(1);
! 		}
! 		lbuf[i] = '\0';
! 		if (symlink(lbuf, target) < 0) {
! 			fprintf(stderr, "mv: symlink failed\n");
! 			return(1);
! 		}
! 	} else if (link(source, target) < 0) {
  		i = fork();
  		if (i == -1) {
  			fprintf(stderr, "mv: try again\n");
-- 
					+-DLS  (dls@j.cc.purdue.edu)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads