From d0181b8fcdac761afec252151a8bfda116916e96 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 19 Oct 2011 10:51:12 -0700 Subject: allow recovery packages to wipe cache updater now has a function "wipe_cache();" which causes recovery to wipe the cache partition after the successful installation of the package. Move log copying around a bit so logs and the last_install flag file are copied to cache after it's wiped. Bug: 5314244 Change-Id: Id35a9eb6dcd626c8f3a3a0076074f462ed3d44bd --- install.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'install.c') 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; } -- cgit v1.2.3