Commit 02f92d56 authored by Ivan Čukić's avatar Ivan Čukić 👁
Browse files

Explicit lambda captures to avoid future dangling reference bugs

parent 847c1dbe
...@@ -112,28 +112,28 @@ void ResourcesDatabaseInitializer::initDatabase(bool retryOnFail) ...@@ -112,28 +112,28 @@ void ResourcesDatabaseInitializer::initDatabase(bool retryOnFail)
const QDir databaseTestBackupDirectory(databaseTestBackupDirectoryPath); const QDir databaseTestBackupDirectory(databaseTestBackupDirectoryPath);
const QDir databaseWorkingBackupDirectory(databaseWorkingBackupDirectoryPath); const QDir databaseWorkingBackupDirectory(databaseWorkingBackupDirectoryPath);
auto removeDatabaseFiles = [&] (const QDir &dir) { auto removeDatabaseFiles = [] (const QDir &dir) {
return std::all_of(databaseFiles.begin(), databaseFiles.cend(), return std::all_of(databaseFiles.begin(), databaseFiles.cend(),
[&] (const QString &fileName) { [&dir] (const QString &fileName) {
const auto filePath = dir.filePath(fileName); const auto filePath = dir.filePath(fileName);
return !QFile::exists(filePath) || QFile::remove(filePath); return !QFile::exists(filePath) || QFile::remove(filePath);
}); });
}; };
auto copyDatabaseFiles = [&] (const QDir &fromDir, const QDir& toDir) { auto copyDatabaseFiles = [removeDatabaseFiles] (const QDir &fromDir, const QDir& toDir) {
return removeDatabaseFiles(toDir) && return removeDatabaseFiles(toDir) &&
std::all_of(databaseFiles.begin(), databaseFiles.cend(), std::all_of(databaseFiles.begin(), databaseFiles.cend(),
[&] (const QString &fileName) { [&fromDir, &toDir] (const QString &fileName) {
const auto fromFilePath = fromDir.filePath(fileName); const auto fromFilePath = fromDir.filePath(fileName);
const auto toFilePath = toDir.filePath(fileName); const auto toFilePath = toDir.filePath(fileName);
return QFile::copy(fromFilePath, toFilePath); return QFile::copy(fromFilePath, toFilePath);
}); });
}; };
auto databaseFilesExistIn = [&] (const QDir &dir) { auto databaseFilesExistIn = [] (const QDir &dir) {
return dir.exists() && return dir.exists() &&
std::all_of(databaseFiles.begin(), databaseFiles.cend(), std::all_of(databaseFiles.begin(), databaseFiles.cend(),
[&] (const QString &fileName) { [&dir] (const QString &fileName) {
const auto filePath = dir.filePath(fileName); const auto filePath = dir.filePath(fileName);
return QFile::exists(filePath); return QFile::exists(filePath);
}); });
...@@ -168,7 +168,7 @@ void ResourcesDatabaseInitializer::initDatabase(bool retryOnFail) ...@@ -168,7 +168,7 @@ void ResourcesDatabaseInitializer::initDatabase(bool retryOnFail)
if (d->database) { if (d->database) {
qCDebug(KAMD_LOG_RESOURCES) << "Database opened successfully"; qCDebug(KAMD_LOG_RESOURCES) << "Database opened successfully";
QObject::connect(d->database.get(), &Common::Database::error, QObject::connect(d->database.get(), &Common::Database::error,
[=] (const QSqlError &error) { [databaseTestBackupDirectory, removeDatabaseFiles] (const QSqlError &error) {
const QString errorLog = const QString errorLog =
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ QStringLiteral("/kactivitymanagerd/resources/errors.log"); + QStringLiteral("/kactivitymanagerd/resources/errors.log");
......
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