Verified Commit 57248775 authored by Andre Heinecke's avatar Andre Heinecke
Browse files

Improve error handling of seckey export

This fetches errors that are not reported by GPGSM when
creating a secret key export by checking for non zero
output (GnuPG Bug #5145) and by the way fixes exporting
to Unicode filenames by using qt instead of passing
the filename to GPG.
parent 4ccbaec6
Pipeline #41391 canceled with stage
......@@ -24,6 +24,8 @@
#include <gpgme++/key.h>
#include <KLocalizedString>
#include <QFile>
#include <QProcess>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -98,7 +100,7 @@ QStringList ExportSecretKeyCommand::arguments() const
result << gpgSmPath();
}
result << QStringLiteral("--yes") << QStringLiteral("--output") << m_filename;
result << QStringLiteral("--yes") << QStringLiteral("--output") << QStringLiteral("-");
if (m_armor) {
result << QStringLiteral("--armor");
......@@ -147,6 +149,29 @@ QString ExportSecretKeyCommand::errorExitMessage(const QStringList &args) const
QString ExportSecretKeyCommand::successMessage(const QStringList &) const
{
if (mHasError) {
return QString();
}
return i18nc("@info", "Secret key successfully exported.");
}
void ExportSecretKeyCommand::postSuccessHook(QWidget *)
{
Q_ASSERT (process());
const auto data = process()->readAllStandardOutput();
if (!data.size()) {
d->error (i18nc("@info", "Possibly bad passphrase given."),
errorCaption());
mHasError = true;
return;
}
QFile file(m_filename);
/* The filedialog already asked for replace ok. */
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
if (file.write(data) != data.size()) {
d->error(i18nc("@info", "Failed to write data."),
errorCaption());
mHasError = true;
}
file.close();
}
......@@ -41,6 +41,7 @@ public:
private:
bool preStartHook(QWidget *) const override;
void postSuccessHook(QWidget *) override;
QStringList arguments() const override;
......@@ -54,6 +55,7 @@ private:
private:
mutable QString m_filename;
mutable bool m_armor;
bool mHasError = false;
};
}
......
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