Remove leftover update workspace folders on launcher startup (#1782)

* Remove leftover update workspace folders on launcher startup

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Skip recently active update workspaces during cleanup

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Keep update workspaces for an hour before cleanup so Windows downloads are not removed

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: nmzik <Nmzik@mail.ru>
This commit is contained in:
Felipe
2026-10-21 15:43:30 -03:00
committed by GitHub
parent f0e55803ba
commit 80932f8da1
+22 -1
View File
@@ -4,6 +4,7 @@
#include <QAbstractButton> #include <QAbstractButton>
#include <QApplication> #include <QApplication>
#include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QDesktopServices> #include <QDesktopServices>
#include <QDir> #include <QDir>
@@ -96,7 +97,27 @@ bool UpdateChecker::IsSupported() {
void UpdateChecker::ShowPreviousResult(QWidget* parent) { void UpdateChecker::ShowPreviousResult(QWidget* parent) {
const auto directory = InstallDirectory(); const auto directory = InstallDirectory();
QFile result(QDir(directory).filePath(QStringLiteral(".kyty-update-result"))); if (!directory.isEmpty()) {
// The helper cannot delete its own executable on Windows, so its workspace is
// removed by the next launcher start.
const QDir install(directory);
for (const auto& name:
install.entryList({QStringLiteral(".kyty-update-??????")},
QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot)) {
QDir workspace(install.filePath(name));
QDateTime newest = QFileInfo(workspace.path()).lastModified();
for (const auto& entry: workspace.entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden |
QDir::NoDotAndDotDot)) {
newest = qMax(newest, entry.lastModified());
}
// A workspace touched recently may belong to a running download or helper. Windows
// lists a file still being downloaded with a stale time, so allow a generous margin.
if (newest.secsTo(QDateTime::currentDateTime()) > 60 * 60) {
workspace.removeRecursively();
}
}
}
QFile result(QDir(directory).filePath(QStringLiteral(".kyty-update-result")));
if (directory.isEmpty() || !result.open(QIODevice::ReadOnly)) { if (directory.isEmpty() || !result.open(QIODevice::ReadOnly)) {
return; return;
} }