summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@pelagicore.com>2019-07-02 18:38:50 +0200
committerBernd Weimer <bernd.weimer@pelagicore.com>2019-08-01 13:21:08 +0200
commitef66fc9984a21cb5ef5d4f660172848c19603caf (patch)
treed9e7eae08b2af0aafae66956262bdd3a36a49f6a
parent93bc72664091403d3c1cbd64274faf3ef31cc902 (diff)
Make sure the app-db is flushed after writing
Otherwise we might end up with a 0-byte app db, if the AM gets killed before the OS (notably Windows) has synced the data to disk. Cherry-picked from dev: 071799b Task-number: AUTOSUITE-1096 Change-Id: Ifacf4854ab3f2b454d098a7b503b3922f72f9742 Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r--src/main-lib/main.cpp2
-rw-r--r--src/manager-lib/applicationdatabase.cpp2
2 files changed, 4 insertions, 0 deletions
diff --git a/src/main-lib/main.cpp b/src/main-lib/main.cpp
index 84b48de7..22a4abf5 100644
--- a/src/main-lib/main.cpp
+++ b/src/main-lib/main.cpp
@@ -424,6 +424,8 @@ void Main::loadApplicationDatabase(const QString &databasePath, bool recreateDat
if (singleApp.isEmpty()) {
if (!QFile::exists(databasePath)) // make sure to create a database on the first run
recreateDatabase = true;
+ if (QFileInfo(databasePath).size() == 0) // cope with Windows' 0-byte left-overs
+ recreateDatabase = true;
if (recreateDatabase) {
const QString dbDir = QFileInfo(databasePath).absolutePath();
diff --git a/src/manager-lib/applicationdatabase.cpp b/src/manager-lib/applicationdatabase.cpp
index 1b336a9b..a6fb8ef3 100644
--- a/src/manager-lib/applicationdatabase.cpp
+++ b/src/manager-lib/applicationdatabase.cpp
@@ -167,6 +167,8 @@ void ApplicationDatabase::write(const QVector<AbstractApplication *> &apps) Q_DE
if (ds.status() != QDataStream::Ok)
throw Exception(*d->file, "could not write to application database");
+
+ d->file->flush();
}
void ApplicationDatabase::invalidate()