feat(logs): narrate what pacman and flatpak really run

Changing screen is not an operation, and a navigation line per click buried
the entries that matter. Providers now narrate the work itself instead: the
exact command, the fallbacks and the counts, through a Qt-free trace sink that
reaches the journal only, so the status bar stays short.
This commit is contained in:
BlackAngelTV committed 2026-10-03 22:38:00 +02:00
1 parent 3ca9c412d2
commit 28bef75bf6
8 files changed
+157 -48

No files matched your search

+43 -5
View File
@@ -1,6 +1,7 @@
#include "pacman-manager.h"
#include "progress-tracker.h"
#include "provider-trace.h"
#include <array>
#include <cctype>
@@ -43,6 +44,13 @@ static std::string shellQuote(const std::string& s) {
return out;
}
// One line of operator trace: the exact command run, a query served from cache,
// what a listing found. The host routes it to the journal only (see
// provider-trace.h), so being verbose here costs nothing in the interface.
static void trace(const std::string& message) {
provider_trace::report("pacman", message);
}
// Keep only the last few lines of a command output for error dialogs, so a
// failure shows the real cause without dumping pages of progress lines.
static std::string lastOutputLines(const std::string& output, int keep = 5) {
@@ -75,6 +83,9 @@ static std::string lastOutputLines(const std::string& output, int keep = 5) {
static std::string execPrivileged(const std::string& pacmanCmd,
const std::string& password,
ProgressCallback progressCallback) {
// The journal gets the command as the user would type it. The password is
// piped to sudo on stdin and must never reach the trace.
trace("$ sudo " + pacmanCmd);
const std::string full = "printf '%s\\n' " + shellQuote(password)
+ " | sudo -S " + pacmanCmd + " 2>&1";
return runWithProgress(full, progressCallback);
@@ -106,10 +117,20 @@ static constexpr std::chrono::seconds kQueryTtl{10};
std::string PacmanManager::cachedQuery(PacmanManager::CachedQuery& slot,
const char* command) {
const auto now = std::chrono::steady_clock::now();
bool fromCache = false;
{
std::lock_guard<std::mutex> lock(m_queryMutex);
if (slot.valid && now - slot.fetched < kQueryTtl) return slot.output;
fromCache = slot.valid && now - slot.fetched < kQueryTtl;
}
if (fromCache) {
// Reused for a few seconds: saying so explains why a page opened
// without spawning pacman at all.
trace(std::string("cache · ") + command);
std::lock_guard<std::mutex> lock(m_queryMutex);
return slot.output;
}
trace(std::string("$ ") + command);
// Queried outside the lock: a second thread asking for the same query then
// just runs it too, which is cheaper than serialising the whole app on
@@ -180,7 +201,9 @@ std::vector<PackageInfo> PacmanManager::search(const std::string& query) {
results.back().description = desc;
}
}
trace("pacman -Ss " + query + " → " + std::to_string(results.size())
+ " résultat(s)");
return results;
}
@@ -291,6 +314,8 @@ std::vector<PackageInfo> PacmanManager::listInstalled() {
}
}
trace("pacman -Q / -Qi / -Sl → " + std::to_string(packages.size())
+ " paquet(s) installé(s), taille et dépôt inclus");
return packages;
}
@@ -322,7 +347,11 @@ std::vector<PackageInfo> PacmanManager::listUpdates() {
// Cached like the other read-only queries: the dashboard badge, the updates
// screen and the "Tout mettre à jour" button all ask for it within the same
// second, and one pacman process answers for all of them.
return parseUpdatesOutput(cachedQuery(m_updatesQuery, "pacman -Qu 2>&1"));
std::vector<PackageInfo> results =
parseUpdatesOutput(cachedQuery(m_updatesQuery, "pacman -Qu 2>&1"));
trace("pacman -Qu → " + std::to_string(results.size())
+ " mise(s) à jour disponible(s)");
return results;
}
// Orphans (-Qdt: no installed package requires them) and legacy packages (-Qm:
@@ -330,8 +359,15 @@ std::vector<PackageInfo> PacmanManager::listUpdates() {
std::vector<PackageInfo> PacmanManager::listCleanupCandidates() {
// `pacman -Qdt` warns on stderr when the system has no orphan at all: only
// stdout is parsed, so the warning never reaches the candidate list.
return parseCleanupOutput(exec("pacman -Qdt 2>/dev/null"),
exec("pacman -Qm 2>/dev/null"));
std::vector<PackageInfo> results = parseCleanupOutput(exec("pacman -Qdt 2>/dev/null"),
exec("pacman -Qm 2>/dev/null"));
int orphans = 0;
for (const auto& pkg : results) {
if (pkg.orphan) ++orphans;
}
trace("pacman -Qdt / -Qm → " + std::to_string(orphans) + " orphelin(s) et "
+ std::to_string(results.size() - orphans) + " paquet(s) legacy");
return results;
}
bool PacmanManager::removePackages(const std::vector<std::string>& packages,
@@ -760,6 +796,7 @@ bool PacmanManager::releaseDatabaseLock(const LockHolder& holder,
if (holder.pid > 0) {
const std::string who = describeLockHolder(holder);
trace("db.lck détenu par " + who + " : envoi de SIGTERM");
if (progressCallback) progressCallback("Arrêt de " + who + "...", -1);
if (!terminateProcess(holder.pid, "TERM")) {
@@ -781,6 +818,7 @@ bool PacmanManager::releaseDatabaseLock(const LockHolder& holder,
// No process left to stop (or it would not die): the lock file itself is
// what keeps the database closed.
trace("aucun processus à arrêter : suppression du fichier de verrou résiduel");
if (progressCallback) progressCallback("Suppression du verrou résiduel...", -1);
if (removeLockFile()) return true;