mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-07-07 20:14:12 +02:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user