perf(progress): report real progress instead of a bouncing bar
pacman restarts its "(1/24)" counter at every phase of a transaction, so the bar was fed 0 percent, 100 percent, 0 percent again a few times per update — and Flatpak/AUR buffered their whole output, which left it indeterminate for the entire run. A shared ProgressTracker now folds every counter, file percentage and package step into one value that only moves forward, the providers stream their output as it is produced, and each provider owns a slice of the bar so a multi-provider update keeps advancing. pacman -Qu is cached like the other read queries, so the sidebar badge, the updates screen and the update button share a single process. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
ed58e87520
commit
b26e907221
12 files changed
+590
-138
No files matched your search
@@ -1,4 +1,7 @@
|
||||
#include "aur-manager.h"
|
||||
|
||||
#include "progress-tracker.h"
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
@@ -18,17 +21,6 @@ static std::string exec(const char* cmd) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Stream command output lines to the progress callback (text-only,
|
||||
// percent = -1 keeps the UI bar indeterminate).
|
||||
static void streamOutput(const std::string& output, ProgressCallback cb) {
|
||||
if (!cb) return;
|
||||
std::istringstream iss(output);
|
||||
std::string line;
|
||||
while (std::getline(iss, line)) {
|
||||
if (!line.empty()) cb(line, -1);
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the tail of a command's output so the user sees the real failure.
|
||||
static std::string lastOutputLines(const std::string& output, int maxLines = 4) {
|
||||
std::istringstream iss(output);
|
||||
@@ -166,9 +158,11 @@ bool AurManager::install(const std::string& packageName,
|
||||
return false;
|
||||
}
|
||||
if (progressCallback) progressCallback("Installation AUR de " + packageName + "...", -1);
|
||||
// Helpers handle sudo themselves; run so the prompt reaches the user.
|
||||
std::string output = exec((h + " -S --noconfirm " + packageName + " 2>&1").c_str());
|
||||
streamOutput(output, progressCallback);
|
||||
// Helpers handle sudo themselves; run so the prompt reaches the user. The
|
||||
// output is streamed: the helpers build with makepkg and then hand over to
|
||||
// pacman, and both report progress as they go.
|
||||
std::string output = runWithProgress(
|
||||
h + " -S --noconfirm " + packageName + " 2>&1", progressCallback);
|
||||
if (system((h + " -Q " + packageName + " > /dev/null 2>&1").c_str()) != 0) {
|
||||
m_lastError = lastOutputLines(output);
|
||||
return false;
|
||||
@@ -185,8 +179,8 @@ bool AurManager::remove(const std::string& packageName,
|
||||
return false;
|
||||
}
|
||||
if (progressCallback) progressCallback("Suppression de " + packageName + "...", -1);
|
||||
std::string output = exec((h + " -R --noconfirm " + packageName + " 2>&1").c_str());
|
||||
streamOutput(output, progressCallback);
|
||||
std::string output = runWithProgress(
|
||||
h + " -R --noconfirm " + packageName + " 2>&1", progressCallback);
|
||||
if (system((h + " -Q " + packageName + " > /dev/null 2>&1").c_str()) == 0) {
|
||||
m_lastError = lastOutputLines(output);
|
||||
return false;
|
||||
@@ -204,8 +198,8 @@ bool AurManager::update(const std::string& packageName,
|
||||
}
|
||||
std::string target = packageName.empty() ? "--aur" : packageName;
|
||||
if (progressCallback) progressCallback("Mise a jour AUR...", -1);
|
||||
std::string output = exec((h + " -Syu --noconfirm " + target + " 2>&1").c_str());
|
||||
streamOutput(output, progressCallback);
|
||||
std::string output = runWithProgress(
|
||||
h + " -Syu --noconfirm " + target + " 2>&1", progressCallback);
|
||||
if (output.find("error:") != std::string::npos
|
||||
|| output.find("erreur") != std::string::npos) {
|
||||
m_lastError = lastOutputLines(output);
|
||||
@@ -222,8 +216,7 @@ bool AurManager::refresh(ProgressCallback progressCallback) {
|
||||
return false;
|
||||
}
|
||||
if (progressCallback) progressCallback("Rafraichissement AUR...", -1);
|
||||
std::string output = exec((h + " -Sy 2>&1").c_str());
|
||||
streamOutput(output, progressCallback);
|
||||
std::string output = runWithProgress(h + " -Sy 2>&1", progressCallback);
|
||||
if (output.find("error:") != std::string::npos
|
||||
|| output.find("erreur") != std::string::npos) {
|
||||
m_lastError = lastOutputLines(output);
|
||||
|
||||
Reference in new issue
Block a user