fix(update): report the newest known version, not just the compiled one
Trusting the version compiled into the binary alone made the app report a stale release whenever the build predated a version bump: `version` is read at configure time, and bumping it is not by itself a reason to configure again, so `cmake --build` kept the previous number compiled in while the marker it installed next to the binary said otherwise. The update was then offered again even though it had just been applied. The version file is now a configure dependency, so a bump reconfigures the build, and the reported version is the newest of the two sources, so neither side can drag the app backwards. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
fb5c11e153
commit
5216480d81
6 files changed
+75
-31
No files matched your search
+19
-12
@@ -51,21 +51,28 @@ UpdateManager::UpdateManager(QObject* parent) : QObject(parent) {
|
||||
});
|
||||
}
|
||||
|
||||
QString UpdateManager::currentVersion() {
|
||||
// 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();
|
||||
QString UpdateManager::newestVersion(const QString& a, const QString& b) {
|
||||
// isNewerVersion() also normalises a leading "v", so "v1.4.1" wins over
|
||||
// "1.3.1" and an empty side always loses.
|
||||
return isNewerVersion(b, a) ? b : a;
|
||||
}
|
||||
|
||||
// Fallback for builds that bypass CMake: the `version` file installed next
|
||||
// to the executable.
|
||||
if (version.isEmpty()) {
|
||||
QFile f(QCoreApplication::applicationDirPath() + "/version");
|
||||
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
version = QString::fromUtf8(f.readAll()).trimmed();
|
||||
}
|
||||
QString UpdateManager::currentVersion() {
|
||||
// Two places know the version, and either can lag behind: the version
|
||||
// compiled into the binary (a build made without configuring again keeps the
|
||||
// previous one) and the marker installed next to the executable (an install
|
||||
// made before an update left the old one behind). Reporting the lower of the
|
||||
// two would offer an already installed release again at every launch, so the
|
||||
// newest one known wins.
|
||||
const QString compiled = QStringLiteral(FWSPACMANAGE_VERSION).trimmed();
|
||||
|
||||
QString installed;
|
||||
QFile file(QCoreApplication::applicationDirPath() + "/version");
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
installed = QString::fromUtf8(file.readAll()).trimmed();
|
||||
}
|
||||
|
||||
const QString version = newestVersion(compiled, installed);
|
||||
return version.isEmpty() ? QStringLiteral("1.0.0") : version;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user