From 328686f925be6cea97f75ceceaa212a31ba16a5c Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 4 Jan 2009 13:27:36 -0600 Subject: Make patch work with -R when deleting files. --- toys/patch.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/toys/patch.c b/toys/patch.c index 62996538..cf22ecb5 100644 --- a/toys/patch.c +++ b/toys/patch.c @@ -196,6 +196,7 @@ done: 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 @@ void patch_main(void) 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; -- cgit v1.2.3