From bc53fe8e356ca642680e90682285bd5e8d98ecb5 Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Wed, 21 May 2025 00:17:38 +0100 Subject: [PATCH] prefix is at start of string, substr between prefix and % --- selfdrive/ui/installer/installer.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/selfdrive/ui/installer/installer.cc b/selfdrive/ui/installer/installer.cc index 4f2d7147a5..c0c528509f 100644 --- a/selfdrive/ui/installer/installer.cc +++ b/selfdrive/ui/installer/installer.cc @@ -94,9 +94,9 @@ int cachedFetch(const std::string &cache) { int executeGitCommand(const std::string &cmd) { static const std::array stages = { // prefix, weight in percentage - std::pair{"Receiving objects: ", 91}, - std::pair{"Resolving deltas: ", 2}, - std::pair{"Updating files: ", 7}, + std::pair{std::string("Receiving objects: "), 91}, + std::pair{std::string("Resolving deltas: "), 2}, + std::pair{std::string("Updating files: "), 7}, }; FILE *pipe = popen(cmd.c_str(), "r"); @@ -107,10 +107,10 @@ int executeGitCommand(const std::string &cmd) { std::string line(buffer); int base = 0; for (const auto &[text, weight] : stages) { - if (line.find(text) != std::string::npos) { + if (line.rfind(text, 0) == 0) { size_t percentPos = line.find("%"); - if (percentPos != std::string::npos && percentPos >= 3) { - int percent = std::stoi(line.substr(percentPos - 3, 3)); + if (percentPos != std::string::npos) { + int percent = std::stoi(line.substr(text.size(), percentPos - text.size())); int progress = base + int(percent / 100. * weight); renderProgress(progress); }