Commit e1e62711 authored by Ragnar Thomsen's avatar Ragnar Thomsen

Fix testing encrypted archives for integrity

Enable testing of encrypted archives by passing the password switch to
the cli programs. When we don't know the password we disable the Test
action with an explanation in the tooltip.

Differential Revision: D2227
parent 32832943
......@@ -222,7 +222,7 @@ bool CliInterface::testArchive()
cacheParameterList();
m_operationMode = Test;
const auto args = substituteTestVariables(m_param.value(TestArgs).toStringList());
const auto args = substituteTestVariables(m_param.value(TestArgs).toStringList(), password());
if (!runProcess(m_param.value(TestProgram).toStringList(), args)) {
return false;
......@@ -739,7 +739,7 @@ QStringList CliInterface::substituteCommentVariables(const QStringList &commentA
return args;
}
QStringList CliInterface::substituteTestVariables(const QStringList &testArgs)
QStringList CliInterface::substituteTestVariables(const QStringList &testArgs, const QString &password)
{
// Required if we call this function from unit tests.
cacheParameterList();
......@@ -753,6 +753,11 @@ QStringList CliInterface::substituteTestVariables(const QStringList &testArgs)
continue;
}
if (arg == QLatin1String("$PasswordSwitch")) {
args << passwordSwitch(password);
continue;
}
args << arg;
}
......@@ -1072,7 +1077,7 @@ void CliInterface::handleLine(const QString& line)
if (checkForPasswordPromptMessage(line)) {
qCDebug(ARK) << "Found a password prompt";
emit error(i18n("Ark does not currently support testing password-protected archives."));
emit error(i18n("Ark does not currently support testing this archive."));
killProcess();
return;
}
......
......@@ -313,7 +313,7 @@ public:
QStringList substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QString &password, bool encryptHeader, int compLevel);
QStringList substituteDeleteVariables(const QStringList &deleteArgs, const QVariantList &files, const QString &password);
QStringList substituteCommentVariables(const QStringList &commentArgs, const QString &commentFile);
QStringList substituteTestVariables(const QStringList &testArgs);
QStringList substituteTestVariables(const QStringList &testArgs, const QString &password);
/**
* @return The preserve path switch, according to the @p preservePaths extraction option.
......
......@@ -425,8 +425,11 @@ void Part::updateActions()
m_addFilesAction->setToolTip(xi18nc("@info:tooltip",
"Adding files to existing password-protected archives with no header-encryption is currently not supported."
"<nl/><nl/>Extract the files and create a new archive if you want to add files."));
m_testArchiveAction->setToolTip(xi18nc("@info:tooltip",
"Testing password-protected archives with no header-encryption is currently not supported."));
} else {
m_addFilesAction->setToolTip(i18nc("@info:tooltip", "Click to add files to the archive"));
m_testArchiveAction->setToolTip(i18nc("@info:tooltip", "Click to test the archive for integrity"));
}
// Figure out if entry size is larger than preview size limit.
......@@ -479,7 +482,8 @@ void Part::updateActions()
bool supportsTesting = ArchiveFormat::fromMetadata(m_model->archive()->mimeType(), metadata).supportsTesting();
m_testArchiveAction->setEnabled(!isBusy() &&
supportsTesting);
supportsTesting &&
!isEncryptedButUnknownPassword);
} else {
m_commentView->setReadOnly(true);
m_editCommentAction->setText(i18nc("@action:inmenu mutually exclusive with Edit &Comment", "Add &Comment"));
......
......@@ -85,7 +85,8 @@ ParameterList CliPlugin::parameterList() const
<< QStringLiteral("$Archive")
<< QStringLiteral("$Files");
p[TestArgs] = QStringList() << QStringLiteral("t")
<< QStringLiteral("$Archive");
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch");
p[TestPassedPattern] = QStringLiteral("^Everything is Ok$");
p[FileExistsExpression] = QStringList()
......
......@@ -125,7 +125,8 @@ ParameterList CliPlugin::parameterList() const
<< QStringLiteral("$Archive");
p[CommentSwitch] = QStringLiteral("-z$CommentFile");
p[TestArgs] = QStringList() << QStringLiteral("t")
<< QStringLiteral("$Archive");
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch");
p[TestPassedPattern] = QStringLiteral("^All OK$");
}
......
......@@ -123,7 +123,8 @@ ParameterList CliPlugin::parameterList() const
p[DiskFullPatterns] = QStringList() << QStringLiteral("write error \\(disk full\\?\\)")
<< QStringLiteral("No space left on device");
p[TestArgs] = QStringList() << QStringLiteral("-t")
<< QStringLiteral("$Archive");
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch");
p[TestPassedPattern] = QStringLiteral("^No errors detected in compressed data of ");
}
return p;
......
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