Fix Update Linux for CLI

Signed-off-by: Collecting <collecting@noreply.localhost>
This commit is contained in:
Collecting
2025-12-26 03:58:34 +00:00
parent 9b77d94c59
commit 549e7c863f

View File

@@ -194,24 +194,27 @@ void UpdaterService::OnDownloadFinished() {
#elif defined(__linux__)
const char* appimage_env = qgetenv("APPIMAGE").constData();
if (!appimage_env || strlen(appimage_env) == 0) {
emit UpdateError(QStringLiteral("Not running from an AppImage. Manual update required."));
emit UpdateError(QStringLiteral("Not running from an AppImage. Check your PATH."));
update_in_progress.store(false);
return;
}
std::filesystem::path original_path = appimage_env;
std::filesystem::path new_path = original_path.string() + ".new";
// 1. BACKUP LOGIC
if (UISettings::values.updater_enable_backups.GetValue()) {
std::filesystem::path backup_dir = UISettings::values.updater_backup_path.GetValue().empty() ?
(original_path.parent_path() / "backup") : std::filesystem::path(UISettings::values.updater_backup_path.GetValue());
std::error_code ec;
std::filesystem::create_directories(backup_dir, ec);
std::filesystem::copy_file(original_path, backup_dir / ("citron-backup-" + GetCurrentVersion() + ".AppImage"),
std::filesystem::copy_options::overwrite_existing, ec);
std::filesystem::path b_file = backup_dir / ("citron-backup-" + GetCurrentVersion() + ".AppImage");
std::filesystem::copy_file(original_path, b_file, std::filesystem::copy_options::overwrite_existing, ec);
if (ec) LOG_ERROR(Frontend, "Backup failed: {}", ec.message());
}
std::filesystem::path new_path = original_path.string() + ".new";
// 2. SAVE NEW DATA
QFile n_file(QString::fromStdString(new_path.string()));
if (n_file.open(QIODevice::WriteOnly)) {
n_file.write(data);
@@ -222,15 +225,16 @@ void UpdaterService::OnDownloadFinished() {
QFileDevice::ReadOther|QFileDevice::ExeOther);
std::error_code ec;
// TRY RENAME: If this fails because the file is busy, we will fall back to staging.
std::filesystem::rename(new_path, original_path, ec);
if (ec) {
emit UpdateError(QString::fromStdString("Failed to replace AppImage: " + ec.message()));
update_in_progress.store(false);
return;
}
}
LOG_WARNING(Frontend, "Direct replace failed (file busy). Staging update for next launch.");
// We leave .new there and let the next launch handle it, or prompt user.
emit UpdateCompleted(UpdateResult::Success, QStringLiteral("Update downloaded. Please delete the old AppImage and rename the .new file."));
} else {
emit UpdateCompleted(UpdateResult::Success, QStringLiteral("Success"));
}
}
update_in_progress.store(false);
#endif
}