fix(update): replace the running binary atomically and relaunch it
Copying over the executable the update is running from fails with ETXTBSY, so the self-update aborted after a successful build and left the user to restart by hand. Installing through a rename, then handing over to the new build, lets the update complete on its own. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
209e2706ee
commit
4ef37dcda6
6 files changed
+248
-38
No files matched your search
+33
-11
@@ -32,6 +32,8 @@
|
||||
#include <QFileDialog>
|
||||
#include <QTextStream>
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
#include <QProcess>
|
||||
|
||||
#include "app-logging.h"
|
||||
|
||||
@@ -2555,8 +2557,8 @@ void MainWindow::onUpdateCheckFinished(bool hasUpdate, const QString& latestVers
|
||||
|
||||
// Ask the user whether to update now or skip. The update runs in the
|
||||
// background (git pull from a checkout, clone + rebuild, prebuilt unpack,
|
||||
// or tarball rebuild); the running binary stays untouched until the next
|
||||
// launch.
|
||||
// or tarball rebuild); the running binary stays untouched and the app
|
||||
// hands over to the new build once the update succeeds.
|
||||
const UpdateManager::UpdateMethod method = m_updateManager->updateMethod();
|
||||
const QString targetDir = m_updateManager->binDir();
|
||||
|
||||
@@ -2613,21 +2615,41 @@ void MainWindow::onUpdateCheckFinished(bool hasUpdate, const QString& latestVers
|
||||
m_updateManager->performSelfUpdate(sudoPassword);
|
||||
}
|
||||
|
||||
// Called when the background git pull + build finishes. Reports the result in
|
||||
// a dialog so the user knows whether to restart the app.
|
||||
// Called when the background git pull + build finishes. A success hands over to
|
||||
// the freshly installed binary right away; a failure is reported in a dialog.
|
||||
void MainWindow::onSelfUpdateFinished(bool success, const QString& message) {
|
||||
disconnect(m_updateManager, &UpdateManager::selfUpdateFinished,
|
||||
this, &MainWindow::onSelfUpdateFinished);
|
||||
|
||||
if (success) {
|
||||
QMessageBox::information(this, "Mise à jour terminée",
|
||||
QString("<h3>PacManager a été mis à jour</h3>"
|
||||
"<p>La nouvelle version sera active au prochain démarrage.</p>"
|
||||
"<pre>%1</pre>")
|
||||
.arg(message.toHtmlEscaped()));
|
||||
} else {
|
||||
if (!success) {
|
||||
QMessageBox::warning(this, "Échec de la mise à jour",
|
||||
QString("<p>La mise à jour a échoué :</p><pre>%1</pre>")
|
||||
.arg(message.toHtmlEscaped()));
|
||||
return;
|
||||
}
|
||||
|
||||
// The build log is no longer shown to the user, so keep it in the app log
|
||||
// for troubleshooting.
|
||||
qCInfo(pacmgrUpdate) << "self-update output:" << message;
|
||||
|
||||
// Restarting is the only way to run the new build: this process still maps
|
||||
// the inode that was replaced on disk. Ask for a manual restart only when
|
||||
// no runnable binary is there to hand over to.
|
||||
const QString program = UpdateManager::restartProgram(m_updateManager->binDir());
|
||||
if (!program.isEmpty()
|
||||
&& QProcess::startDetached(program, QCoreApplication::arguments().mid(1))) {
|
||||
qCInfo(pacmgrUpdate) << "update installed, relaunching" << program;
|
||||
statusBar()->showMessage("Mise à jour terminée, redémarrage de PacManager...");
|
||||
// Quit on the next event-loop pass so the message paints first. The new
|
||||
// process is detached and outlives this one.
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
return;
|
||||
}
|
||||
|
||||
qCWarning(pacmgrUpdate) << "could not relaunch" << program;
|
||||
QMessageBox::information(this, "Mise à jour terminée",
|
||||
QString("<h3>PacManager a été mis à jour</h3>"
|
||||
"<p>La nouvelle version sera active au prochain démarrage.</p>"
|
||||
"<pre>%1</pre>")
|
||||
.arg(message.toHtmlEscaped()));
|
||||
}
|
||||
Reference in new issue
Block a user