ref: 1355f149c3f7c6abe120d3394ac5dc48632f8945
parent: d5938c597328adb8abb8785b4ac820ca0f094b6b
author: qwx <qwx@sciops.net>
date: Thu Jan 16 11:44:01 EST 2025
patch: fix not applying each input patch file atomically
--- a/sys/man/1/patch
+++ b/sys/man/1/patch
@@ -22,6 +22,10 @@
its original location.
If a hunk does not apply, then the file is left untouched.
.PP
+When multiple patch files are provided, they are applied in order,
+interrupting the process in case of error.
+Successfully applied patches are not rolled back.
+.PP
The following options are supported:
.TP
.B -R
--- a/sys/src/cmd/patch.c
+++ b/sys/src/cmd/patch.c
@@ -627,6 +627,8 @@
curfile = nil;
h = nil;
prevh = nil;
+ nchanged = 0;
+ changed = nil;
for(i = 0; i < p->nhunk; i++){
h = &p->hunk[i];
if(strcmp(h->newpath, "/dev/null") == 0)
@@ -723,8 +725,9 @@
}
freepatch(p);
Bterm(f);
+ finish(ok);
}else{
- for(i = 0; i < argc; i++){
+ for(i = 0; ok && i < argc; i++){
if((f = Bopen(argv[i], OREAD)) == nil)
sysfatal("open %s: %r", argv[i]);
if((p = parse(f, argv[i])) == nil)
@@ -735,8 +738,8 @@
}
freepatch(p);
Bterm(f);
+ finish(ok);
}
}
- finish(ok);
exits(nil);
}
--
⑨