MAKE SOMETIMES REMOVES DIRECTORIES
authorDavid Dawes <dawes@physics.su.OZ.AU>
Mon, 10 Aug 1992 00:00:00 +0000 (00:00 +0000)
committerDavid Dawes <dawes@physics.su.OZ.AU>
Mon, 10 Aug 1992 00:00:00 +0000 (00:00 +0000)
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.

AUTHOR: David Dawes (dawes@physics.su.OZ.AU)
386BSD-Patchkit: patch00039

usr/src/usr.bin/make/compat.c
usr/src/usr.bin/make/job.c

index a213985..6450f6d 100644 (file)
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
+ * --------------------         -----   ----------------------
+ * CURRENT PATCH LEVEL:         1       00039
+ * --------------------         -----   ----------------------
+ *
+ * 10 Aug 92   David Dawes             Fixed "remove directory" bug
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -59,6 +66,7 @@ static char sccsid[] = "@(#)compat.c  5.7 (Berkeley) 3/1/91";
 #include    <sys/wait.h>
 #include    <sys/errno.h>
 #include    <ctype.h>
 #include    <sys/wait.h>
 #include    <sys/errno.h>
 #include    <ctype.h>
+#include    <sys/stat.h>                               /* 10 Aug 92*/
 #include    "make.h"
 extern int errno;
 
 #include    "make.h"
 extern int errno;
 
@@ -80,6 +88,7 @@ static int        CompatRunCommand();
  * CompatInterrupt --
  *     Interrupt the creation of the current target and remove it if
  *     it ain't precious.
  * 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     XXX 10 Aug 92
  *
  * Results:
  *     None.
  *
  * Results:
  *     None.
@@ -95,12 +104,16 @@ CompatInterrupt (signo)
     int            signo;
 {
     GNode   *gn;
     int            signo;
 {
     GNode   *gn;
+    struct stat sbuf;                                  /* 10 Aug 92*/
     
     if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
        char      *file = Var_Value (TARGET, curTarg);
 
     
     if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
        char      *file = Var_Value (TARGET, curTarg);
 
-       if (unlink (file) == SUCCESS) {
-           printf ("*** %s removed\n", file);
+       stat (file, &sbuf);
+       if (!(sbuf.st_mode & S_IFDIR)) {
+           if (unlink (file) == SUCCESS) {
+               printf ("*** %s removed\n", file);
+           }
        }
 
        /*
        }
 
        /*
index eb2375a..82b5f3f 100644 (file)
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
+ * --------------------         -----   ----------------------
+ * CURRENT PATCH LEVEL:         1       00039
+ * --------------------         -----   ----------------------
+ *
+ * 10 Aug 92    David Dawes             Fixed "remove directory" bug
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -2469,8 +2476,13 @@ JobInterrupt (runINTERRUPT)
            char        *file = (job->node->path == (char *)NULL ?
                                 job->node->name :
                                 job->node->path);
            char        *file = (job->node->path == (char *)NULL ?
                                 job->node->name :
                                 job->node->path);
-           if (unlink (file) == 0) {
-               Error ("*** %s removed", file);
+           /* Don't unlink directories */              /* 10 Aug 92*/
+           struct stat sbuf;
+           stat (file, &sbuf);
+           if (!(sbuf.st_mode & S_IFDIR)) {
+               if (unlink (file) == 0) {
+                   Error ("*** %s removed", file);
+               }
            }
        }
 #ifdef RMT_WANTS_SIGNALS
            }
        }
 #ifdef RMT_WANTS_SIGNALS