0
0
mirror of https://github.com/keepassxreboot/keepassxc.git synced 2024-09-20 12:22:16 +02:00

Using saveToFile in Merge command.

This commit is contained in:
Louis-Bertrand Varin 2017-06-14 20:00:09 -04:00
parent f3f6f6a493
commit 46f7d97176

View File

@ -22,12 +22,10 @@
#include <QApplication>
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QSaveFile>
#include <QStringList>
#include <QTextStream>
#include "core/Database.h"
#include "format/KeePass2Writer.h"
#include "gui/UnlockDatabaseDialog.h"
int Merge::execute(int argc, char** argv)
@ -95,26 +93,13 @@ int Merge::execute(int argc, char** argv)
}
db1->merge(db2);
QSaveFile saveFile(args.at(0));
if (!saveFile.open(QIODevice::WriteOnly)) {
qCritical("Unable to open file %s for writing.", qPrintable(args.at(0)));
return EXIT_FAILURE;
}
KeePass2Writer writer;
writer.writeDatabase(&saveFile, db1);
if (writer.hasError()) {
qCritical("Error while updating the database:\n%s\n", qPrintable(writer.errorString()));
return EXIT_FAILURE;
}
if (!saveFile.commit()) {
qCritical("Error while updating the database:\n%s\n", qPrintable(writer.errorString()));
QString errorMessage = db1->saveToFile(args.at(0));
if (!errorMessage.isEmpty()) {
qCritical("Unable to save database to file : %s", qPrintable(errorMessage));
return EXIT_FAILURE;
}
out << "Successfully merged the database files.\n";
return EXIT_SUCCESS;
}