Add rm-on-fail to the hexpatch script, allowing more confidence that repeated make invocations will not accidentally succeed

pull/30/head
Hamish Coleman 7 years ago
parent 93f327106e
commit 4cbc329c4a

@ -218,8 +218,7 @@ $(DEPSDIR)/slice.insert.deps: Makefile
# Generate a working file with any known patches applied
%.img: %.img.orig
cp --reflink=auto $< $@
./scripts/hexpatch.pl $@ $@.d/*.patch
# FIXME - want --rm_on_fail semantics here
./scripts/hexpatch.pl --rm_on_fail $@ $@.d/*.patch
# using both __DIR and __FL2 is a hack to get around needing to quote the
# DOS path separator. It feels like there should be a better way if I put
@ -262,7 +261,7 @@ GETELTORITO := ./scripts/geteltorito
# extract the DOS boot image from an iso (and fix it up so qemu can boot it)
%.img: %.iso
$(GETELTORITO) -o $@ $<
./scripts/hexpatch.pl $@ fix-hdd-image-`stat -c %s $@`.patch
./scripts/hexpatch.pl --rm_on_fail $@ fix-hdd-image-`stat -c %s $@`.patch
$(call build_info,$<.bat)
# $1 is the lenovo named iso

@ -20,7 +20,7 @@ sub usage() {
print("patching the right file\n");
print("\n");
print("Usage:\n");
print(" hexpatch.pl binaryfile patchfile [patchfile...]\n");
print(" hexpatch.pl [--rm_on_fail] binaryfile patchfile [patchfile...]\n");
print("\n");
exit(1);
}
@ -167,7 +167,21 @@ sub apply_patch {
}
}
sub rm_on_fail {
my ($bool, $filename) = @_;
if ($bool) {
unlink($filename);
}
}
sub main() {
my $rm_on_fail;
if (defined($ARGV[0]) && $ARGV[0] eq "--rm_on_fail") {
$rm_on_fail=1;
shift @ARGV;
}
my $binaryfile = shift @ARGV;
if (!defined($binaryfile) or !defined($ARGV[0])) {
usage();
@ -193,11 +207,13 @@ sub main() {
if (!defined($db)) {
warn("Cannot read $patchfile\n");
rm_on_fail($rm_on_fail,$binaryfile);
exit(1);
}
if (!verify_context($db,$fh)) {
warn("The binaryfile does not match the context bytes from $patchfile\n");
rm_on_fail($rm_on_fail,$binaryfile);
exit(1);
}

Loading…
Cancel
Save