1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

SessionManager: Fix fallback to default session if session file is invalid

Creating available sessions metadata is now also faster as it doesn't
need to parse the entire session file, only check for validity.

See #2331
This commit is contained in:
David Rosca 2018-01-03 11:06:21 +01:00
parent 0096801556
commit 0141a2e621
3 changed files with 34 additions and 6 deletions

View File

@ -100,6 +100,32 @@ static void loadVersion3(QDataStream &stream, RestoreData &data)
} }
} }
// static
bool RestoreManager::validateFile(const QString &file)
{
if (!QFile::exists(file)) {
return false;
}
QFile recoveryFile(file);
if (!recoveryFile.open(QIODevice::ReadOnly)) {
return false;
}
QDataStream stream(&recoveryFile);
int version;
stream >> version;
if (version == Qz::sessionVersion || version == 0x0003 || version == (0x0003 | 0x050000)) {
int windowCount;
stream >> windowCount;
return windowCount > 0;
}
return false;
}
// static // static
void RestoreManager::createFromFile(const QString &file, RestoreData &data) void RestoreManager::createFromFile(const QString &file, RestoreData &data)
{ {
@ -108,7 +134,10 @@ void RestoreManager::createFromFile(const QString &file, RestoreData &data)
} }
QFile recoveryFile(file); QFile recoveryFile(file);
recoveryFile.open(QIODevice::ReadOnly); if (!recoveryFile.open(QIODevice::ReadOnly)) {
return;
}
QDataStream stream(&recoveryFile); QDataStream stream(&recoveryFile);
int version; int version;

View File

@ -38,6 +38,7 @@ public:
QObject *recoveryObject(WebPage *page); QObject *recoveryObject(WebPage *page);
static bool validateFile(const QString &file);
static void createFromFile(const QString &file, RestoreData &data); static void createFromFile(const QString &file, RestoreData &data);
private: private:

View File

@ -279,10 +279,8 @@ void SessionManager::fillSessionsMetaDataListIfNeeded()
for (int i = 0; i < sessionFiles.size(); ++i) { for (int i = 0; i < sessionFiles.size(); ++i) {
const QFileInfo &fileInfo = sessionFiles.at(i); const QFileInfo &fileInfo = sessionFiles.at(i);
RestoreData data;
RestoreManager::createFromFile(fileInfo.absoluteFilePath(), data);
if (data.isEmpty()) if (!RestoreManager::validateFile(fileInfo.absoluteFilePath()))
continue; continue;
SessionMetaData metaData; SessionMetaData metaData;
@ -321,8 +319,8 @@ void SessionManager::loadSettings()
m_lastActiveSessionPath = sessionsDir.absoluteFilePath(m_lastActiveSessionPath); m_lastActiveSessionPath = sessionsDir.absoluteFilePath(m_lastActiveSessionPath);
} }
// fallback to default session // Fallback to default session
if (!QFile::exists(m_lastActiveSessionPath)) if (!RestoreManager::validateFile(m_lastActiveSessionPath))
m_lastActiveSessionPath = defaultSessionPath(); m_lastActiveSessionPath = defaultSessionPath();
} }