summaryrefslogtreecommitdiffstats
path: root/install.c
diff options
context:
space:
mode:
Diffstat (limited to 'install.c')
-rw-r--r--install.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/install.c b/install.c
index 707cda438..9d7595e1a 100644
--- a/install.c
+++ b/install.c
@@ -36,11 +36,9 @@
#define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary"
#define PUBLIC_KEYS_FILE "/res/keys"
-static const char *LAST_INSTALL_FILE = "/cache/recovery/last_install";
-
// If the package contains an update binary, extract it and run it.
static int
-try_update_binary(const char *path, ZipArchive *zip) {
+try_update_binary(const char *path, ZipArchive *zip, int* wipe_cache) {
const ZipEntry* binary_entry =
mzFindZipEntry(zip, ASSUMED_UPDATE_BINARY_NAME);
if (binary_entry == NULL) {
@@ -54,7 +52,7 @@ try_update_binary(const char *path, ZipArchive *zip) {
if (fd < 0) {
mzCloseZipArchive(zip);
LOGE("Can't make %s\n", binary);
- return 1;
+ return INSTALL_ERROR;
}
bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd);
close(fd);
@@ -62,7 +60,7 @@ try_update_binary(const char *path, ZipArchive *zip) {
if (!ok) {
LOGE("Can't copy %s\n", ASSUMED_UPDATE_BINARY_NAME);
- return 1;
+ return INSTALL_ERROR;
}
int pipefd[2];
@@ -119,6 +117,8 @@ try_update_binary(const char *path, ZipArchive *zip) {
}
close(pipefd[1]);
+ *wipe_cache = 0;
+
char buffer[1024];
FILE* from_child = fdopen(pipefd[0], "r");
while (fgets(buffer, sizeof(buffer), from_child) != NULL) {
@@ -145,6 +145,8 @@ try_update_binary(const char *path, ZipArchive *zip) {
} else {
ui_print("\n");
}
+ } else if (strcmp(command, "wipe_cache") == 0) {
+ *wipe_cache = 1;
} else {
LOGE("unknown command [%s]\n", command);
}
@@ -236,7 +238,7 @@ exit:
}
static int
-really_install_package(const char *path)
+really_install_package(const char *path, int* wipe_cache)
{
ui_set_background(BACKGROUND_ICON_INSTALLING);
ui_print("Finding update package...\n");
@@ -285,25 +287,24 @@ really_install_package(const char *path)
/* Verify and install the contents of the package.
*/
ui_print("Installing update...\n");
- return try_update_binary(path, &zip);
+ return try_update_binary(path, &zip, wipe_cache);
}
int
-install_package(const char* path)
+install_package(const char* path, int* wipe_cache, const char* install_file)
{
- FILE* install_log = fopen_path(LAST_INSTALL_FILE, "w");
+ FILE* install_log = fopen_path(install_file, "w");
if (install_log) {
fputs(path, install_log);
fputc('\n', install_log);
} else {
LOGE("failed to open last_install: %s\n", strerror(errno));
}
- int result = really_install_package(path);
+ int result = really_install_package(path, wipe_cache);
if (install_log) {
fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log);
fputc('\n', install_log);
fclose(install_log);
- chmod(LAST_INSTALL_FILE, 0644);
}
return result;
}