Article View: gnu.utils.bug
Article #1743Problems with fileutils-1.0/ln.c +fixes
From: Mike Rendell
Date: Wed, 21 Feb 1990 15:36
Date: Wed, 21 Feb 1990 15:36
90 lines
2775 bytes
2775 bytes
Two problems with gnu ln in the fileutils-1.0 distribution:
* does not check to see if it is linking to a directory:
(as root)
# mkdir A
# ln A B
A is a directory
# ln.gnu A B
#
this is hard to fix on some systems (e.g. clri must be used on suns)
* using -f as root can make a mess of the file system:
(as root)
# mkdir A A/B
# ls -ldg A/B
drwxrwx--- 2 michael wheel 512 Feb 21 11:07 A/B
# touch B
# ln.gnu -f B A
# ls -ldg A/B
-rw-rw---- 2 michael wheel 512 Feb 21 11:09 A/B
#
Diffs two fix these problems:
*** /tmp/,RCSt1012657 Wed Feb 21 11:44:38 1990
--- ln.c Wed Feb 21 11:35:24 1990
***************
*** 161,166 ****
--- 168,174 ----
char *new;
{
struct stat stats;
+ int ulink = 0;
if (isdir (new))
{
***************
*** 177,192 ****
if (verbose)
printf (" %s -> %s\n", old, new);
! if (force)
! unlink (new);
else if (interactive && lstat (new, &stats) == 0)
{
if (!confirm (new))
return 0;
else
! unlink (new);
}
!
if ((*linkfunc) (old, new) < 0)
{
fprintf (stderr, "%s: cannot %slink %s to ",
--- 185,216 ----
if (verbose)
printf (" %s -> %s\n", old, new);
! if (isdir(old))
! {
! /* On bsd systems -f means links to directories are ok, on sysV it
! means try to force the link by unlinking the target first.
! Go with the sysV method - /etc/link, should be used to link
! directories. */
! fprintf (stderr, "%s: %s is a directory\n", program, new);
! return 1;
! }
! else if (force)
! ulink = 1;
else if (interactive && lstat (new, &stats) == 0)
{
if (!confirm (new))
return 0;
else
! ulink = 1;
}
!
! /* Watch that we don't try to unlink a directory as this can have bad
! consequences when done by root. */
! if (ulink && !isdir(new))
! {
! unlink(new);
! }
!
if ((*linkfunc) (old, new) < 0)
{
fprintf (stderr, "%s: cannot %slink %s to ",
--
Mike Rendell - Dept. of Comp. Sci, Memorial University of Newfoundland
Technical Details
Message-ID:
<9002211520.AA12764@odie.cs.mun.ca>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!MITVMA.MIT.EDU!michael%odie.cs.mun.caShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!MITVMA.MIT.EDU!michael%odie.cs.mun.ca From: michael%odie.cs.mun.ca@MITVMA.MIT.EDU (Mike Rendell) Newsgroups: gnu.utils.bug Subject: Problems with fileutils-1.0/ln.c +fixes Message-ID: <9002211520.AA12764@odie.cs.mun.ca> Date: 21 Feb 90 15:36:37 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 90