Article View: net.bugs.2bsd
Article #336mv with symbolic links fix
From: David L. Stevens
Date: Sat, 25 Oct 1986 18:44
Date: Sat, 25 Oct 1986 18:44
67 lines
2024 bytes
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)
Technical Details
Message-ID:
<2408@j.cc.purdue.edu>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!dlsShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!dls From: dls@j.cc.purdue.edu (David L. Stevens) Newsgroups: net.bugs.2bsd Subject: mv with symbolic links fix Message-ID: <2408@j.cc.purdue.edu> Date: Sat, 25-Oct-86 13:44:37 EST Article-I.D.: j.2408 Posted: Sat Oct 25 13:44:37 1986 Date-Received: Sun, 26-Oct-86 04:11:35 EST Reply-To: dls@j.cc.purdue.edu.UUCP (David L. Stevens) Organization: PUCC Unix Group Lines: 67