🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.utils.bug
Article #1011

Oops: Improvements for patch 2.0 12g8

#1011
From: Andreas Schwab
Date: Tue, 06 Oct 1992 15:23
84 lines
2793 bytes
Sorry, the patch i posted was wrong. Here is the complete patch again:

Here is a patch to patch which i find very useful: when backing up the
patched file, automagically make the necessary directories. This
allows e.g.:

patch -B orig/ < patchfile

without worrying about directories to be created.
I also added code for systems having the mkdir system call, so that it
isn't necessary to call mkdir via system().

diff -ur orig/config.h.in ./config.h.in
--- orig/config.h.in	Fri Jul 10 23:33:33 1992
+++ ./config.h.in	Tue Oct  6 14:18:57 1992
@@ -6,6 +6,9 @@
 /* Define if the system has strerror().  */
 #undef HAVE_STRERROR
 
+/* Define if the system has mkdir().  */
+#undef HAVE_MKDIR
+
 /* Define if the system has ANSI C header files and library functions.  */
 #undef STDC_HEADERS
 
diff -ur orig/configure.in ./configure.in
--- orig/configure.in	Tue Jul 14 08:40:33 1992
+++ ./configure.in	Tue Oct  6 13:59:29 1992
@@ -16,7 +16,7 @@
 AC_UNISTD_H
 AC_USG
 AC_REPLACE_FUNCS(rename)
-AC_HAVE_FUNCS(strerror)
+AC_HAVE_FUNCS(strerror mkdir)
 AC_ALLOCA
 AC_LONG_FILE_NAMES
 AC_XENIX_DIR
diff -ur orig/util.c ./util.c
--- orig/util.c	Tue Sep 15 04:04:31 1992
+++ ./util.c	Tue Oct  6 14:14:37 1992
@@ -91,7 +91,10 @@
 	if (debug & 4)
 	    say3("Moving %s to %s.\n", to, bakname);
 #endif
-	if (rename(to, bakname) < 0) {
+	if (rename(to, bakname) < 0
+	    && (errno != ENOENT
+		|| (makedirs (bakname, TRUE),
+		    rename (to, bakname) < 0))) {
 	    say4("Can't backup %s, output is in %s: %s\n", to, from,
 		 strerror(errno));
 	    return -1;
@@ -337,6 +340,7 @@
     if (dirvp < 0)
 	return;
 
+#ifndef HAVE_MKDIR
     strcpy(buf, "mkdir");
     s = buf;
     for (i=0; i<=dirvp; i++) {
@@ -351,6 +355,20 @@
     }
     if (s != buf)
 	system(buf);
+#else
+    for (i = 0; i <= dirvp; i++)
+      {
+	struct stat sbuf;
+	if (stat (tmpbuf, &sbuf))
+	  {
+	    if (errno != ENOENT || mkdir (tmpbuf, 0777))
+	      return;
+	  }
+	else if (!S_ISDIR (sbuf.st_mode))
+	  return;
+	*dirv[i] = '/';
+      }
+#endif
 }
 
 /* Make filenames more reasonable. */
--
Andreas Schwab
schwab@ls5.informatik.uni-dortmund.de
Technical Details
Message-ID: <9210061323.AA28819@lamothe.informatik.uni-dortmund.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!lamothe.informatik.uni-dortmund.de!schwab

Show Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!lamothe.informatik.uni-dortmund.de!schwab
From: schwab@lamothe.informatik.uni-dortmund.de (Andreas Schwab)
Subject: Oops: Improvements for patch 2.0 12g8
Message-ID: <9210061323.AA28819@lamothe.informatik.uni-dortmund.de>
Sender: gnulists@ai.mit.edu
Reply-To: schwab@ls5.informatik.uni-dortmund.de (Andreas Schwab)
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 6 Oct 1992 15:23:45 GMT
Approved: bug-gnu-utils@prep.ai.mit.edu
Lines: 85