Skip actively locked autosave files

Check the QLockFile in staleFiles() before returning a no-KF5 recovery candidate, matching the KAutoSaveFile contract that actively owned autosave files are not stale.

Extend the no-KF5 Catch test so a child process keeps the autosave lock alive while allStaleFiles() runs, then verify recovery after the child is killed.

Assisted-by: pi coding agent / Mika (OpenAI GPT-5.5)
This commit is contained in:
Gerhard Schwanzer
2026-07-05 17:39:38 +02:00
parent 7a97e873d9
commit dcec0bf7ff
2 changed files with 51 additions and 5 deletions
+21 -2
View File
@@ -48,6 +48,11 @@ QString metadataFileName(const QString &autosave_file_name)
return autosave_file_name + QStringLiteral(".path");
}
QString lockFileName(const QString &autosave_file_name)
{
return autosave_file_name + QStringLiteral(".lock");
}
QUrl normalizeManagedFile(const QUrl &url)
{
if (url.isEmpty()) {
@@ -165,6 +170,18 @@ QStringList findAllStaleFiles(const QString &application_name)
return files;
}
bool autosaveFileIsRecoverable(const QString &autosave_file_name)
{
QLockFile lock(lockFileName(autosave_file_name));
lock.setStaleLockTime(60 * 1000);
if (!lock.tryLock()) {
return false;
}
lock.unlock();
return true;
}
} // namespace
KAutoSaveFile::KAutoSaveFile(const QUrl &filename, QObject *parent) :
@@ -239,8 +256,7 @@ bool KAutoSaveFile::open(OpenMode openmode)
}
if (!m_lock) {
m_lock = std::make_unique<QLockFile>(
fileName() + QStringLiteral(".lock"));
m_lock = std::make_unique<QLockFile>(lockFileName(fileName()));
m_lock->setStaleLockTime(60 * 1000);
}
@@ -268,6 +284,9 @@ QList<KAutoSaveFile *> KAutoSaveFile::staleFiles(
&& managed_file != managed_file_filter) {
continue;
}
if (!autosaveFileIsRecoverable(file)) {
continue;
}
auto *stale_file = new KAutoSaveFile(managed_file);
stale_file->setFileName(file);