Commit 9cac6b3b authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Ensure auto-saved file is newer than project before proposing to recover data.

BUG: 424016
parent 3b4a143a
...@@ -429,6 +429,11 @@ bool ProjectManager::checkForBackupFile(const QUrl &url, bool newFile) ...@@ -429,6 +429,11 @@ bool ProjectManager::checkForBackupFile(const QUrl &url, bool newFile)
const QString projectId = QCryptographicHash::hash(url.fileName().toUtf8(), QCryptographicHash::Md5).toHex(); const QString projectId = QCryptographicHash::hash(url.fileName().toUtf8(), QCryptographicHash::Md5).toHex();
QUrl autosaveUrl = newFile ? url : QUrl::fromLocalFile(QFileInfo(url.path()).absoluteDir().absoluteFilePath(projectId + QStringLiteral(".kdenlive"))); QUrl autosaveUrl = newFile ? url : QUrl::fromLocalFile(QFileInfo(url.path()).absoluteDir().absoluteFilePath(projectId + QStringLiteral(".kdenlive")));
QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(autosaveUrl); QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(autosaveUrl);
QFileInfo sourceInfo(url.toLocalFile());
QDateTime sourceTime;
if (sourceInfo.exists()) {
sourceTime = QFileInfo(url.toLocalFile()).lastModified();
}
KAutoSaveFile *orphanedFile = nullptr; KAutoSaveFile *orphanedFile = nullptr;
// Check if we can have a lock on one of the file, // Check if we can have a lock on one of the file,
// meaning it is not handled by any Kdenlive instance // meaning it is not handled by any Kdenlive instance
...@@ -436,14 +441,16 @@ bool ProjectManager::checkForBackupFile(const QUrl &url, bool newFile) ...@@ -436,14 +441,16 @@ bool ProjectManager::checkForBackupFile(const QUrl &url, bool newFile)
for (KAutoSaveFile *stale : staleFiles) { for (KAutoSaveFile *stale : staleFiles) {
if (stale->open(QIODevice::QIODevice::ReadWrite)) { if (stale->open(QIODevice::QIODevice::ReadWrite)) {
// Found orphaned autosave file // Found orphaned autosave file
orphanedFile = stale; if (!sourceTime.isValid() || QFileInfo(stale->fileName()).lastModified() > sourceTime) {
break; orphanedFile = stale;
break;
}
} }
} }
} }
if (orphanedFile) { if (orphanedFile) {
if (KMessageBox::questionYesNo(nullptr, i18n("Auto-saved files exist. Do you want to recover them now?"), i18n("File Recovery"), if (KMessageBox::questionYesNo(nullptr, i18n("Auto-saved file exist. Do you want to recover now?"), i18n("File Recovery"),
KGuiItem(i18n("Recover")), KGuiItem(i18n("Do not recover"))) == KMessageBox::Yes) { KGuiItem(i18n("Recover")), KGuiItem(i18n("Do not recover"))) == KMessageBox::Yes) {
doOpenFile(url, orphanedFile); doOpenFile(url, orphanedFile);
return true; return true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment