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 "flatpak-manager.h"
#include "progress-tracker.h"
#include "provider-trace.h"
#include <array>
#include <atomic>
@@ -20,6 +21,13 @@
namespace fs = std::filesystem;
// One line of operator trace: the exact command run, the decision taken around
// it, 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("flatpak", message);
}
// The per-user standard XDG data dir (~/.local/share).
static fs::path userShareDir() {
const char* home = std::getenv("HOME");
@@ -266,6 +274,7 @@ private:
// commands themselves stay silent for minutes at a time, and these are the only
// lines the user gets while a runtime comes down.
static std::string runFlatpak(const std::string& command, ProgressCallback callback) {
trace("$ " + command);
DownloadWatcher watcher(callback);
return runWithProgress(command, callback);
}
@@ -591,6 +600,8 @@ static std::set<std::string> appIdsInOutput(const std::string& output) {
std::vector<PackageInfo> FlatpakManager::search(const std::string& query) {
std::string cmd = "flatpak search " + query + " 2>&1";
std::vector<PackageInfo> results = parseSearchOutput(exec(cmd.c_str()));
trace("flatpak search " + query + " → " + std::to_string(results.size())
+ " résultat(s)");
// Report the honest status of each hit (already installed / pending
// update) so the search page does not keep showing "Disponible" for apps
@@ -614,14 +625,21 @@ std::vector<PackageInfo> FlatpakManager::listInstalled() {
// ref, branch and installation are what tell two installations of the same
// application id apart, so they are listed: without them the view could
// neither show the copies nor choose between them.
return parseInstalledOutput(exec("flatpak list --app "
"--columns=application,version,origin,ref,branch,installation "
"2>&1"));
std::vector<PackageInfo> results =
parseInstalledOutput(exec("flatpak list --app "
"--columns=application,version,origin,ref,branch,installation "
"2>&1"));
trace("flatpak list → " + std::to_string(results.size())
+ " application(s) installée(s), copies comprises");
return results;
}
std::vector<PackageInfo> FlatpakManager::listUpdates() {
return parseUpdatesOutput(
std::vector<PackageInfo> results = parseUpdatesOutput(
exec("flatpak remote-ls --updates --columns=application,version 2>&1"));
trace("flatpak remote-ls --updates → " + std::to_string(results.size())
+ " mise(s) à jour disponible(s)");
return results;
}
bool FlatpakManager::isInstalled(const std::string& appId) {
@@ -637,6 +655,7 @@ bool FlatpakManager::install(const std::string& packageName,
// as installed without re-running the installer, then made sure it appears
// in the desktop launcher (covers apps installed before this feature).
if (isInstalled(packageName)) {
trace("déjà installé : " + packageName + " — aucune installation lancée");
if (progressCallback) progressCallback(packageName + " est déjà installé.", -1);
integrateDesktopEntries(packageName);
return true;
@@ -656,6 +675,7 @@ bool FlatpakManager::install(const std::string& packageName,
// one (idempotent, per-user) so the install can resolve the app.
exec("flatpak remote-add --if-not-exists --user flathub "
"https://flathub.org/repo/flathub.flatpakrepo 2>&1");
trace("remote flathub vérifié (--user, --if-not-exists)");
std::string output = tryInstall("");
@@ -674,6 +694,8 @@ bool FlatpakManager::install(const std::string& packageName,
// repeating a doomed attempt.
if (output.find("error:") != std::string::npos && !isInstalled(packageName)
&& (noRefs() || ambiguous())) {
trace(ambiguous() ? "dépôts multiples : passage en --user flathub"
: "références distantes obsolètes : actualisation d'appstream");
if (progressCallback) progressCallback("Mise à jour des métadonnées des dépôts...", -1);
runFlatpak("flatpak update --appstream 2>&1", progressCallback);
output = tryInstall(ambiguous() ? "--user flathub" : "");
@@ -681,6 +703,7 @@ bool FlatpakManager::install(const std::string& packageName,
// Remaining failures get one per-user attempt (no polkit, no ambiguity).
if (output.find("error:") != std::string::npos && !isInstalled(packageName)) {
trace("échec en système : nouvel essai en installation utilisateur (flathub)");
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
output = tryInstall("--user flathub");
}
@@ -688,6 +711,7 @@ bool FlatpakManager::install(const std::string& packageName,
// The authoritative success check is `flatpak info`; the output may carry
// noise such as "already installed" that must not count as a failure.
if (!isInstalled(packageName)) {
trace("échec : `flatpak info " + packageName + "` ne trouve rien après les essais");
m_lastError = lastOutputLines(output);
return false;
}
@@ -768,9 +792,12 @@ void FlatpakManager::uninstallDesktopEntries(const std::string& appId) {
}
void FlatpakManager::integrateAllInstalled() {
for (const auto& pkg : listInstalled()) {
const std::vector<PackageInfo> installed = listInstalled();
for (const auto& pkg : installed) {
integrateDesktopEntries(pkg.name);
}
trace("intégration du lanceur : " + std::to_string(installed.size())
+ " application(s) re-liée(s)");
}
bool FlatpakManager::remove(const std::string& packageName,
@@ -810,6 +837,8 @@ bool FlatpakManager::remove(const std::string& packageName,
m_lastError = lastOutputLines(output);
return false;
}
trace("appel ambigu pour " + appId + " : " + std::to_string(targets.size())
+ " copie(s) à supprimer une par une");
}
bool success = true;
@@ -854,6 +883,8 @@ bool FlatpakManager::update(const std::string& packageName,
m_lastError = lastOutputLines(output);
return false;
}
trace("appel ambigu pour " + packageName + " : "
+ std::to_string(targets.size()) + " copie(s) mise(s) à jour");
bool success = true;
for (const std::string& target : targets) {
const std::string copy = runFlatpak(updateCommand(target), progressCallback);
@@ -867,6 +898,7 @@ bool FlatpakManager::update(const std::string& packageName,
// System-wide updates need polkit: fall back to the per-user installation.
if (output.find("error:") != std::string::npos) {
trace("échec en système (polkit ?) : nouvel essai en installation utilisateur");
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
output = tryUpdate("--user");
}
@@ -888,6 +920,7 @@ bool FlatpakManager::refresh(ProgressCallback progressCallback) {
// System remotes need polkit for that: fall back to the user installation.
if (output.find("error:") != std::string::npos) {
trace("appstream système refusé (polkit ?) : nouvel essai en --user");
exec("flatpak remote-add --if-not-exists --user flathub "
"https://flathub.org/repo/flathub.flatpakrepo 2>&1");
output = runFlatpak("flatpak update --appstream --user 2>&1", progressCallback);
@@ -934,6 +967,7 @@ bool FlatpakManager::installFile(const std::string& path,
// Registering a repository is the whole job, and the per-user scope avoids
// polkit on a machine where the user is not an administrator.
if (kind == FileKind::Repo) {
trace("fichier .flatpakrepo : enregistrement du dépôt " + repoNamespace(path));
if (progressCallback) {
progressCallback("Ajout du dépôt " + repoNamespace(path) + "...", -1);
}
@@ -958,6 +992,7 @@ bool FlatpakManager::installFile(const std::string& path,
// A system-wide install needs polkit: fall back to the per-user one, exactly
// like a name-based install does.
if (output.find("error:") != std::string::npos) {
trace("fichier " + path + " : échec en système, nouvel essai en utilisateur");
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
output = runFlatpak(installFileCommand(kind, path, /*userScope=*/true), progressCallback);
}
@@ -974,8 +1009,11 @@ bool FlatpakManager::installFile(const std::string& path,
// invisible in the desktop menu.
const std::set<std::string> appIds = appIdsInOutput(output);
if (appIds.empty()) {
trace("aucun identifiant lisible dans la sortie : ré-intégration de tout");
integrateAllInstalled();
} else {
trace("intégration du lanceur : " + std::to_string(appIds.size())
+ " application(s) issue(s) du fichier");
for (const auto& appId : appIds) integrateDesktopEntries(appId);
}
return true;
+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;