fix(update): stamp the installed release so it is not offered twice

The checkout path installed with the build's configured prefix instead of
installing into the directory holding the running copy, so the binary in use
and its version marker both stayed at the old release: the app kept reporting
that version and offered the same update again at every launch.

Every method now stages and installs into the running binary's directory, the
install step writes the release it just installed next to the binary, and
currentVersion() reads the version compiled into the running build first,
falling back to the marker file. The repo-root `version` file stays the single
source of truth: CMake compiles it in.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
BlackAngelTV committed 2026-09-12 22:19:47 +02:00
1 parent 632cdf1dea
commit 5756704b03
5 files changed
+132 -42

No files matched your search

+3 -2
View File
@@ -3009,10 +3009,11 @@ void MainWindow::onUpdateCheckFinished(bool hasUpdate, const QString& latestVers
}
// Prompt for the sudo password only when the update must write into a
// root-owned directory (e.g. /usr/bin). Only the final copy is privileged:
// root-owned directory (e.g. /usr/bin). Every method installs into the
// running binary's directory, and only that final copy is privileged:
// everything else builds in a temp directory owned by the user.
QString sudoPassword;
if (m_updateManager->repoPath().isEmpty() && !QFileInfo(targetDir).isWritable()
if (!QFileInfo(targetDir).isWritable()
&& m_pacman && m_pacman->isAvailable()) {
bool ok = false;
sudoPassword = QInputDialog::getText(
+49 -34
View File
@@ -16,7 +16,14 @@
// The app is hosted at https://gitea.nocode-var.tech/FWS/FWS-PacManage.
static const char* kApiUrl =
"https://gitea.nocode-var.tech/api/v1/repos/FWS/FWS-PacManage/releases/latest";
static const char* kVersionToken = "FWSPACMANAGE_VERSION"; // replaced at build time
// Version compiled in from the repo-root `version` file (see CMakeLists.txt).
// Empty when the build bypasses CMake, in which case the `version` file next to
// the executable is used instead.
#ifndef FWSPACMANAGE_VERSION
#define FWSPACMANAGE_VERSION ""
#endif
static const char* kRepoUrl =
"https://gitea.nocode-var.tech/FWS/FWS-PacManage.git";
@@ -45,23 +52,21 @@ UpdateManager::UpdateManager(QObject* parent) : QObject(parent) {
}
QString UpdateManager::currentVersion() {
// The `version` file at the repo root is the single source of truth. It is
// read from the executable's directory so a running build always reports
// the same version the developer bumped in the repo.
QString version;
const QString localFile = QCoreApplication::applicationDirPath() + "/version";
QFile f(localFile);
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
version = QString::fromUtf8(f.readAll()).trimmed();
}
// The compiled-in version wins: it describes the code that is actually
// running, so a `version` file left behind (or never refreshed) by an
// update cannot make the app re-offer a release it already installed.
QString version = QStringLiteral(FWSPACMANAGE_VERSION).trimmed();
// Fallback for builds that bypass CMake: the `version` file installed next
// to the executable.
if (version.isEmpty()) {
// CMake configure-time token; falls back to 1.0.0 when built without.
version = QString::fromLatin1(kVersionToken);
if (version == QLatin1String("FWSPACMANAGE_VERSION")) {
version = QStringLiteral("1.0.0");
QFile f(QCoreApplication::applicationDirPath() + "/version");
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
version = QString::fromUtf8(f.readAll()).trimmed();
}
}
return version;
return version.isEmpty() ? QStringLiteral("1.0.0") : version;
}
QString UpdateManager::stateFilePath() {
@@ -390,7 +395,7 @@ void UpdateManager::performSelfUpdate(const QString& sudoPassword) {
<< static_cast<int>(method) << "into" << binDir();
switch (method) {
case UpdateMethod::Checkout:
performCheckoutUpdate();
performCheckoutUpdate(sudoPassword);
return;
case UpdateMethod::Clone:
performCloneUpdate(sudoPassword);
@@ -408,13 +413,14 @@ void UpdateManager::performSelfUpdate(const QString& sudoPassword) {
}
}
// Checkout path (dev): pull the sources and rebuild in place, then install
// with whatever prefix the build directory was configured with.
void UpdateManager::performCheckoutUpdate() {
QString script = QStringLiteral(
"set -e\n"
"echo 'Mise a jour de PacManager...'\n"
"export GIT_TERMINAL_PROMPT=0\n"
// Checkout path (dev, or any tree built from a clone): pull, rebuild, then
// install into the directory that holds the running binary — like every other
// method. The build's configured prefix is deliberately not used: it generally
// points at a system directory the app cannot write, and installing there would
// leave the copy in use (and its version marker) untouched.
void UpdateManager::performCheckoutUpdate(const QString& sudoPassword) {
QString script = updateScriptPrologue();
script += QStringLiteral(
"git pull --ff-only origin main 2>&1 || git pull --ff-only 2>&1\n"
"if [ -d build ]; then\n"
" cmake --build build -j$(nproc) 2>&1\n"
@@ -422,15 +428,17 @@ void UpdateManager::performCheckoutUpdate() {
" cmake -B build -DCMAKE_BUILD_TYPE=Release . 2>&1\n"
" cmake --build build -j$(nproc) 2>&1\n"
"fi\n"
"cmake --install build 2>&1\n"
"echo 'Mise a jour terminee.'");
"cmake --install build --prefix \"$STAGE\" 2>&1\n");
script += installCommand(quotedPassword(sudoPassword), stagedInstallScript());
script += QStringLiteral("echo 'Mise a jour terminee.'");
runShell(script, m_repoPath);
}
// Shared prologue for the installed (no checkout) paths: temp work directory
// with a cleanup trap, plus the paths the install step needs, exported so the
// sudo-wrapped `sh -c` copy can expand them.
QString UpdateManager::installedScriptPrologue() const {
// Shared prologue for every update path: temp work directory with a cleanup
// trap, and the paths the install step needs, exported so the sudo-wrapped
// `sh -c` copy can expand them. APP_VERSION is the release being installed; the
// checkout path sets it too, so all four methods stamp the same marker.
QString UpdateManager::updateScriptPrologue() const {
return QStringLiteral(
"set -e\n"
"echo 'Mise a jour de PacManager...'\n"
@@ -438,9 +446,10 @@ QString UpdateManager::installedScriptPrologue() const {
"trap 'rm -rf \"$WORK\"' EXIT\n"
"BIN_DIR=%1\n"
"STAGE=\"$WORK/stage\"\n"
"export WORK BIN_DIR STAGE\n"
"APP_VERSION=%2\n"
"export WORK BIN_DIR STAGE APP_VERSION\n"
"export GIT_TERMINAL_PROMPT=0\n")
.arg(quotedBinDir());
.arg(quotedBinDir(), quoteShell(m_lastKnownRemoteVersion));
}
// Copies a staged install tree ($STAGE/bin, plugins under bin/plugins or
@@ -465,6 +474,12 @@ QString UpdateManager::stagedInstallScript() {
"}\n"
"mkdir -p \"$BIN_DIR\"\n"
"install_file \"$STAGE/bin/PacManager\" \"$BIN_DIR/PacManager\"\n"
// The version marker has to follow the installed release: it is what
// the app reports and what the next update check compares against, so
// a stale one would offer the same release again at every launch.
"if [ -n \"$APP_VERSION\" ]; then\n"
" printf '%s\\n' \"$APP_VERSION\" > \"$STAGE/bin/version\"\n"
"fi\n"
"if [ -f \"$STAGE/bin/version\" ]; then\n"
" install_file \"$STAGE/bin/version\" \"$BIN_DIR/version\"\n"
"fi\n"
@@ -519,7 +534,7 @@ QString UpdateManager::quotedPassword(const QString& sudoPassword) {
// ones fast-forward it, then the app is rebuilt and installed where the
// running binary lives.
void UpdateManager::performCloneUpdate(const QString& sudoPassword) {
QString script = installedScriptPrologue();
QString script = updateScriptPrologue();
script += QStringLiteral(
"SRC=%1\n"
"export SRC\n"
@@ -548,7 +563,7 @@ void UpdateManager::performCloneUpdate(const QString& sudoPassword) {
// Prebuilt path: download the release archive (bin/ + plugins/) and unpack it
// straight into the running binary's directory. No compiler needed.
void UpdateManager::performPrebuiltUpdate(const QString& sudoPassword) {
QString script = installedScriptPrologue();
QString script = updateScriptPrologue();
script += QStringLiteral(
"URL=%1\n"
"ARCHIVE=\"$WORK/update.tar.gz\"\n"
@@ -570,7 +585,7 @@ void UpdateManager::performPrebuiltUpdate(const QString& sudoPassword) {
// Source fallback: fetch the release tarball, build it in /tmp and install the
// result where the running binary lives. Used only when git is unavailable.
void UpdateManager::performTarballUpdate(const QString& sudoPassword) {
QString script = installedScriptPrologue();
QString script = updateScriptPrologue();
script += QStringLiteral(
"command -v cmake >/dev/null 2>&1 || { echo 'cmake est requis pour la mise a jour'; exit 1; }\n"
"URL=%1\n"