Commit 7addb6b7 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Fix Delete action on header-encrypted archives

Forward-port of cdcd6c13.
parent ac2dbbac
......@@ -202,28 +202,14 @@ bool CliInterface::deleteFiles(const QList<QVariant> & files)
cacheParameterList();
m_operationMode = Delete;
//start preparing the argument list
QStringList args = m_param.value(DeleteArgs).toStringList();
//now replace the various elements in the list
for (int i = 0; i < args.size(); ++i) {
QString argument = args.at(i);
qCDebug(ARK) << "Processing argument " << argument;
if (argument == QLatin1String( "$Archive" )) {
args[i] = filename();
} else if (argument == QLatin1String( "$Files" )) {
args.removeAt(i);
for (int j = 0; j < files.count(); ++j) {
args.insert(i + j, escapeFileName(files.at(j).toString()));
++i;
}
--i;
}
}
m_removedFiles = files;
const auto deleteArgs = m_param.value(DeleteArgs).toStringList();
const auto args = substituteDeleteVariables(deleteArgs,
files,
password());
if (!runProcess(m_param.value(DeleteProgram).toStringList(), args)) {
return false;
}
......@@ -684,6 +670,41 @@ QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, con
return args;
}
QStringList CliInterface::substituteDeleteVariables(const QStringList &deleteArgs, const QVariantList &files, const QString &password)
{
cacheParameterList();
QStringList args;
foreach (const QString& arg, deleteArgs) {
qCDebug(ARK) << "Processing argument" << arg;
if (arg == QLatin1String("$Archive")) {
args << filename();
continue;
}
if (arg == QLatin1String("$PasswordSwitch")) {
args << passwordSwitch(password);
continue;
}
if (arg == QLatin1String("$Files")) {
foreach (const QVariant& file, files) {
args << escapeFileName(file.toString());
}
continue;
}
// Simple argument (e.g. d in rar), nothing to substitute, just add it to the list.
args << arg;
}
// Remove empty strings, if any.
args.removeAll(QString());
return args;
}
QStringList CliInterface::substituteCommentVariables(const QStringList &commentArgs, const QString &commentFile)
{
// Required if we call this function from unit tests.
......
......@@ -322,6 +322,7 @@ public:
QStringList substituteListVariables(const QStringList &listArgs, const QString &password);
QStringList substituteCopyVariables(const QStringList &extractArgs, const QVariantList &files, bool preservePaths, const QString &password, const QString &rootNode);
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);
......
......@@ -81,6 +81,7 @@ ParameterList CliPlugin::parameterList() const
<< QStringLiteral("$CompressionLevelSwitch")
<< QStringLiteral("$Files");
p[DeleteArgs] = QStringList() << QStringLiteral("d")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$Archive")
<< QStringLiteral("$Files");
p[TestArgs] = QStringList() << QStringLiteral("t")
......
......@@ -99,6 +99,7 @@ ParameterList CliPlugin::parameterList() const
p[PasswordHeaderSwitch] = QStringList() << QStringLiteral("-hp$Password");
p[CompressionLevelSwitch] = QStringLiteral("-m$CompressionLevel");
p[DeleteArgs] = QStringList() << QStringLiteral( "d" )
<< QStringLiteral( "$PasswordSwitch" )
<< QStringLiteral( "$Archive" )
<< QStringLiteral( "$Files" );
p[FileExistsExpression] = QStringList()
......
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