*BSD News Article 3426


Return to BSD News archive

Newsgroups: comp.unix.bsd
Path: sserve!manuel!munnari.oz.au!metro!news
From: dawes@physics.su.OZ.AU (David Dawes)
Subject: make(1) unlinking directories
Message-ID: <1992Aug10.062618.27013@ucc.su.OZ.AU>
Sender: news@ucc.su.OZ.AU
Nntp-Posting-Host: physics.su.oz.au
Organization: School of Physics, University of Sydney, Australia
Date: Mon, 10 Aug 1992 06:26:18 GMT
Lines: 96

I was building X386 this morning, and when I interrupted 'make' it
told me it had removed a directory.  I checked and it really had unlinked
it.  (I got it back by booting the fixit disk and running fsck.)

I've patched the make source so that it won't do this anymore.  Here are
my patches:


*** compat.c.orig	Mon May 11 13:54:28 1992
--- compat.c	Mon Aug 10 14:36:41 1992
***************
*** 59,64 ****
--- 59,65 ----
  #include    <sys/wait.h>
  #include    <sys/errno.h>
  #include    <ctype.h>
+ #include    <sys/stat.h>
  #include    "make.h"
  extern int errno;
  
***************
*** 80,85 ****
--- 81,87 ----
   * CompatInterrupt --
   *	Interrupt the creation of the current target and remove it if
   *	it ain't precious.
+  *	Don't unlink it if it is a directory
   *
   * Results:
   *	None.
***************
*** 95,106 ****
      int	    signo;
  {
      GNode   *gn;
      
      if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
  	char 	  *file = Var_Value (TARGET, curTarg);
  
! 	if (unlink (file) == SUCCESS) {
! 	    printf ("*** %s removed\n", file);
  	}
  
  	/*
--- 97,112 ----
      int	    signo;
  {
      GNode   *gn;
+     struct stat sbuf;
      
      if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
  	char 	  *file = Var_Value (TARGET, curTarg);
  
! 	stat (file, &sbuf);
! 	if (!(sbuf.st_mode & S_IFDIR)) {
! 	    if (unlink (file) == SUCCESS) {
! 		printf ("*** %s removed\n", file);
! 	    }
  	}
  
  	/*
*** job.c.orig	Mon May 11 13:55:59 1992
--- job.c	Mon Aug 10 14:30:44 1992
***************
*** 2469,2476 ****
  	    char  	*file = (job->node->path == (char *)NULL ?
  				 job->node->name :
  				 job->node->path);
! 	    if (unlink (file) == 0) {
! 		Error ("*** %s removed", file);
  	    }
  	}
  #ifdef RMT_WANTS_SIGNALS
--- 2469,2481 ----
  	    char  	*file = (job->node->path == (char *)NULL ?
  				 job->node->name :
  				 job->node->path);
! 	    /* Don't unlink directories */
! 	    struct stat	sbuf;
! 	    stat (file, &sbuf);
! 	    if (!(sbuf.st_mode & S_IFDIR)) {
! 		if (unlink (file) == 0) {
! 		    Error ("*** %s removed", file);
! 		}
  	    }
  	}
  #ifdef RMT_WANTS_SIGNALS



David
--
------------------------------------------------------------------------------
 David Dawes (dawes@physics.su.oz.au)    DoD#210      | Phone: +61 2 692 2639
 School of Physics, University of Sydney, Australia   | Fax:   +61 2 660 2903
------------------------------------------------------------------------------