CLI Merge: Only save database file when modified. (#2466)

* Merge: detect if database was changed.
* Adding unit test.
* Only saving on change.
This commit is contained in:
louib 2018-11-09 21:59:16 -05:00 committed by Jonathan White
parent a7dd9f19f4
commit f06742cf41
2 changed files with 19 additions and 6 deletions

View file

@ -84,14 +84,18 @@ int Merge::execute(const QStringList& arguments)
}
Merger merger(db2.data(), db1.data());
merger.merge();
bool databaseChanged = merger.merge();
QString errorMessage = db1->saveToFile(args.at(0));
if (!errorMessage.isEmpty()) {
err << QObject::tr("Unable to save database to file : %1").arg(errorMessage) << endl;
return EXIT_FAILURE;
if (databaseChanged) {
QString errorMessage = db1->saveToFile(args.at(0));
if (!errorMessage.isEmpty()) {
err << QObject::tr("Unable to save database to file : %1").arg(errorMessage) << endl;
return EXIT_FAILURE;
}
out << "Successfully merged the database files." << endl;
} else {
out << "Database was not modified by merge operation." << endl;
}
out << "Successfully merged the database files." << endl;
return EXIT_SUCCESS;
}