changeset 335:556c10abdff6

Make patch work with -R when deleting files.
author Rob Landley <rob@landley.net>
date Sun, 04 Jan 2009 13:27:36 -0600
parents 83c461db9df7
children 0c816f5abe22
files toys/patch.c
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/toys/patch.c	Sat Jan 03 18:15:18 2009 -0600
+++ b/toys/patch.c	Sun Jan 04 13:27:36 2009 -0600
@@ -196,6 +196,7 @@
 
 void patch_main(void)
 {
+	int reverse = toys.optflags & FLAG_REVERSE;
 	if (TT.infile) TT.filepatch = xopen(TT.infile, O_RDONLY);
 	TT.filein = TT.fileout = -1;
 
@@ -255,12 +256,17 @@
 			if (!strncmp(s, "\t1969-12-31", 10)) start = "/dev/null";
 			*s = 0;
 
+			if (reverse) {
+				s = start;
+				start = TT.oldname;
+			}
+
 			// If new file is /dev/null (before -p), we're deleting oldname
 			if (!strcmp(start, "/dev/null")) {
-				start = TT.oldname;
+				start = reverse ? s : TT.oldname;
 				del++;
 			} else start = patchline+4;
-				
+
 			// handle -p path truncation.
 			for (s = start; *s;) {
 				if ((toys.optflags & FLAG_PATHLEN) && TT.prefix == i) break;