aboutsummaryrefslogtreecommitdiff
path: root/toys/patch.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2009-01-04 13:27:36 -0600
committerRob Landley <rob@landley.net>2009-01-04 13:27:36 -0600
commit328686f925be6cea97f75ceceaa212a31ba16a5c (patch)
tree3c3d7938a9c7a4f05371b53737acc19faf77e522 /toys/patch.c
parent7e849c5b99e539f5af5262d8ade6b9791463c796 (diff)
downloadtoybox-328686f925be6cea97f75ceceaa212a31ba16a5c.tar.gz
Make patch work with -R when deleting files.
Diffstat (limited to 'toys/patch.c')
-rw-r--r--toys/patch.c10
1 files 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;