From d441d52540a4e8edd0fa33d8c6a7c43ce609bd8f Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Thu, 4 May 2023 15:27:34 -0700 Subject: [PATCH] =?UTF-8?q?Fail=C2=A0on=C2=A0fastboot-info.txt=C2=A0format?= =?UTF-8?q?=C2=A0error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If fastboot-info.txt has wrong format we should not fall back on hardcoded list silently. Instead we should LOG(FATAL) and fail. Hardcoded list should only be used when fastboot-info.txt is not found or is empty  Test:  fastboot flashall  Bug: 194686221 Change-Id: I1cada102f3ff12c1f3002d0b61d3785fc25543c1 --- fastboot/fastboot.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 73884abb5..f09616a49 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -1724,8 +1724,6 @@ std::vector> ParseFastbootInfo(const FlashingPlan* fp, } auto task = ParseFastbootInfoLine(fp, command); if (!task) { - LOG(ERROR) << "Error when parsing fastboot-info.txt, falling back on Hardcoded list: " - << text; return {}; } tasks.emplace_back(std::move(task)); @@ -1751,8 +1749,6 @@ std::vector> ParseFastbootInfo(const FlashingPlan* fp, } std::vector> ParseFastbootInfo(const FlashingPlan* fp, std::ifstream& fs) { - if (!fs || fs.eof()) return {}; - std::string text; std::vector file; // Get os_partitions that need to be resized @@ -1783,13 +1779,17 @@ void FlashAllTool::Flash() { std::string path = find_item_given_name("fastboot-info.txt"); std::ifstream stream(path); - std::vector> tasks = ParseFastbootInfo(fp_, stream); - if (tasks.empty()) { + if (!stream || stream.eof()) { LOG(VERBOSE) << "Flashing from hardcoded images. fastboot-info.txt is empty or does not " "exist"; HardcodedFlash(); return; } + + std::vector> tasks = ParseFastbootInfo(fp_, stream); + if (tasks.empty()) { + LOG(FATAL) << "Invalid fastboot-info.txt file."; + } LOG(VERBOSE) << "Flashing from fastboot-info.txt"; for (auto& task : tasks) { task->Run();