Add "require partition-exists=" support.
The Pixel 2 system images release was a bit of a disaster because anyone
using an old version of fastboot would blindly flash too few partitions,
potentially bricking their device. This change lets us add a line to
the android-info.txt file for a device with a new partition.
Also error out sooner in such cases by checking the requirements
immediately, rather than optimistically unpacking everything first.
Switch Action over to C++ to fix memory issues.
Bug: http://b/77158188 (partition checking)
Bug: http://b/74444116 (error out sooner)
Test: manual testing with a modified android-info.txt
Change-Id: I58b426cad410107e368f35f5725216d07281dd97
diff --git a/fastboot/util.cpp b/fastboot/util.cpp
index f2bbd34..fb085e7 100644
--- a/fastboot/util.cpp
+++ b/fastboot/util.cpp
@@ -35,35 +35,24 @@
#include "fastboot.h"
-double now()
-{
+double now() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
}
-char *mkmsg(const char *fmt, ...)
-{
- char buf[256];
- char *s;
- va_list ap;
-
- va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- va_end(ap);
-
- s = strdup(buf);
- if (s == 0) die("out of memory");
- return s;
-}
-
-void die(const char *fmt, ...)
-{
+void die(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
fprintf(stderr,"error: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr,"\n");
va_end(ap);
- exit(1);
+ exit(EXIT_FAILURE);
+}
+
+char* xstrdup(const char* s) {
+ char* result = strdup(s);
+ if (!result) die("out of memory");
+ return result;
}