Article View: gnu.utils.bug
Article #1013Improvements for patch 2.0 12g8
From: Andreas Schwab
Date: Tue, 06 Oct 1992 15:01
Date: Tue, 06 Oct 1992 15:01
69 lines
2323 bytes
2323 bytes
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/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 13:59:30 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 != EPATH
+ || (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:
<9210061301.AA28803@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!schwabShow 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: Improvements for patch 2.0 12g8 Message-ID: <9210061301.AA28803@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:01:17 GMT Approved: bug-gnu-utils@prep.ai.mit.edu Lines: 70