diff options
author | Tao Bao <tbao@google.com> | 2016-09-27 00:20:15 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-09-27 00:20:15 +0200 |
commit | 13414c6a0430358f6f5631481017cc677a53e4b2 (patch) | |
tree | 4894ba778a43e4e9e48a841a5c4ef834808ce437 | |
parent | resolve merge conflicts of d5c7d6b to nyc-mr1-dev-plus-aosp (diff) | |
parent | Duplicate the last_install content into last_log. (diff) | |
download | android_bootable_recovery-13414c6a0430358f6f5631481017cc677a53e4b2.tar android_bootable_recovery-13414c6a0430358f6f5631481017cc677a53e4b2.tar.gz android_bootable_recovery-13414c6a0430358f6f5631481017cc677a53e4b2.tar.bz2 android_bootable_recovery-13414c6a0430358f6f5631481017cc677a53e4b2.tar.lz android_bootable_recovery-13414c6a0430358f6f5631481017cc677a53e4b2.tar.xz android_bootable_recovery-13414c6a0430358f6f5631481017cc677a53e4b2.tar.zst android_bootable_recovery-13414c6a0430358f6f5631481017cc677a53e4b2.zip |
Diffstat (limited to '')
-rw-r--r-- | install.cpp | 60 | ||||
-rw-r--r-- | recovery.cpp | 19 |
2 files changed, 41 insertions, 38 deletions
diff --git a/install.cpp b/install.cpp index d600ea330..9a83c4884 100644 --- a/install.cpp +++ b/install.cpp @@ -517,13 +517,6 @@ install_package(const char* path, bool* wipe_cache, const char* install_file, modified_flash = true; auto start = std::chrono::system_clock::now(); - FILE* install_log = fopen_path(install_file, "w"); - if (install_log) { - fputs(path, install_log); - fputc('\n', install_log); - } else { - PLOG(ERROR) << "failed to open last_install"; - } int result; std::vector<std::string> log_buffer; if (setup_install_mounts() != 0) { @@ -532,33 +525,40 @@ install_package(const char* path, bool* wipe_cache, const char* install_file, } else { result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); } - if (install_log != nullptr) { - fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log); - fputc('\n', install_log); - std::chrono::duration<double> duration = std::chrono::system_clock::now() - start; - int count = static_cast<int>(duration.count()); - // Report the time spent to apply OTA update in seconds. - fprintf(install_log, "time_total: %d\n", count); - fprintf(install_log, "retry: %d\n", retry_count); - - for (const auto& s : log_buffer) { - fprintf(install_log, "%s\n", s.c_str()); - } - if (ensure_path_mounted(UNCRYPT_STATUS) != 0) { - LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS; + // Measure the time spent to apply OTA update in seconds. + std::chrono::duration<double> duration = std::chrono::system_clock::now() - start; + int time_total = static_cast<int>(duration.count()); + + if (ensure_path_mounted(UNCRYPT_STATUS) != 0) { + LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS; + } else { + std::string uncrypt_status; + if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) { + PLOG(WARNING) << "failed to read uncrypt status"; + } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_time:")) { + PLOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status; } else { - std::string uncrypt_status; - if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) { - PLOG(WARNING) << "failed to read uncrypt status"; - } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_time:")) { - PLOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status; - } else { - fprintf(install_log, "%s\n", android::base::Trim(uncrypt_status).c_str()); - } + log_buffer.push_back(android::base::Trim(uncrypt_status)); } - fclose(install_log); } + + // The first two lines need to be the package name and install result. + std::vector<std::string> log_header = { + path, + result == INSTALL_SUCCESS ? "1" : "0", + "time_total: " + std::to_string(time_total), + "retry: " + std::to_string(retry_count), + }; + std::string log_content = android::base::Join(log_header, "\n") + "\n" + + android::base::Join(log_buffer, "\n"); + if (!android::base::WriteStringToFile(log_content, install_file)) { + PLOG(ERROR) << "failed to write " << install_file; + } + + // Write a copy into last_log. + LOG(INFO) << log_content; + return result; } diff --git a/recovery.cpp b/recovery.cpp index e0f5a2ee3..c7d840dd6 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -1431,15 +1431,18 @@ static bool bootreason_in_blacklist() { } static void log_failure_code(ErrorCode code, const char *update_package) { - FILE* install_log = fopen_path(TEMPORARY_INSTALL_FILE, "w"); - if (install_log != nullptr) { - fprintf(install_log, "%s\n", update_package); - fprintf(install_log, "0\n"); - fprintf(install_log, "error: %d\n", code); - fclose(install_log); - } else { - PLOG(ERROR) << "failed to open last_install"; + std::vector<std::string> log_buffer = { + update_package, + "0", // install result + "error: " + std::to_string(code), + }; + std::string log_content = android::base::Join(log_buffer, "\n"); + if (!android::base::WriteStringToFile(log_content, TEMPORARY_INSTALL_FILE)) { + PLOG(ERROR) << "failed to write " << TEMPORARY_INSTALL_FILE; } + + // Also write the info into last_log. + LOG(INFO) << log_content; } static ssize_t logbasename( |