Commit 27e5167b authored by Elvis Angelaccio's avatar Elvis Angelaccio

Drop RootNode extraction option

We never set this option and because of this there is a lot of unused code (e.g. all the `RootNodeSwitch` stuff).

Digging in the history, the last time that this option was set was in commit 10bc72f4.
This means that this option is fully superseded by `fileNodeRootPair` and we can safely discard all this unused code.

Closes T1942

Differential Revision: D1704
parent 1b812373
......@@ -372,7 +372,7 @@ void Cli7zTest::testExtractArgs()
QFETCH(bool, preservePaths);
QFETCH(QString, password);
QStringList replacedArgs = plugin->substituteCopyVariables(extractArgs, files, preservePaths, password, QString());
QStringList replacedArgs = plugin->substituteCopyVariables(extractArgs, files, preservePaths, password);
QVERIFY(replacedArgs.size() >= extractArgs.size());
QFETCH(QStringList, expectedArgs);
......
......@@ -329,74 +329,69 @@ void CliRarTest::testExtractArgs_data()
QTest::addColumn<QVariantList>("files");
QTest::addColumn<bool>("preservePaths");
QTest::addColumn<QString>("password");
QTest::addColumn<QString>("rootNode");
QTest::addColumn<QStringList>("expectedArgs");
QTest::newRow("preserve paths, encrypted, root node")
QTest::newRow("preserve paths, encrypted")
<< QStringLiteral("/tmp/foo.rar")
<< QVariantList {
QVariant::fromValue(fileRootNodePair(QStringLiteral("aDir/b.txt"), QStringLiteral("aDir"))),
QVariant::fromValue(fileRootNodePair(QStringLiteral("c.txt"), QString()))
}
<< true << QStringLiteral("1234") << QStringLiteral("aDir")
<< true << QStringLiteral("1234")
<< QStringList {
QStringLiteral("-kb"),
QStringLiteral("-p-"),
QStringLiteral("x"),
QStringLiteral("-p1234"),
QStringLiteral("-apaDir"),
QStringLiteral("/tmp/foo.rar"),
QStringLiteral("aDir/b.txt"),
QStringLiteral("c.txt"),
};
QTest::newRow("preserve paths, unencrypted, root node")
QTest::newRow("preserve paths, unencrypted")
<< QStringLiteral("/tmp/foo.rar")
<< QVariantList {
QVariant::fromValue(fileRootNodePair(QStringLiteral("aDir/b.txt"), QStringLiteral("aDir"))),
QVariant::fromValue(fileRootNodePair(QStringLiteral("c.txt"), QString()))
}
<< true << QString() << QStringLiteral("aDir")
<< true << QString()
<< QStringList {
QStringLiteral("-kb"),
QStringLiteral("-p-"),
QStringLiteral("x"),
QStringLiteral("-apaDir"),
QStringLiteral("/tmp/foo.rar"),
QStringLiteral("aDir/b.txt"),
QStringLiteral("c.txt"),
};
QTest::newRow("without paths, encrypted, root node")
QTest::newRow("without paths, encrypted")
<< QStringLiteral("/tmp/foo.rar")
<< QVariantList {
QVariant::fromValue(fileRootNodePair(QStringLiteral("aDir/b.txt"), QStringLiteral("aDir"))),
QVariant::fromValue(fileRootNodePair(QStringLiteral("c.txt"), QString()))
}
<< false << QStringLiteral("1234") << QStringLiteral("aDir")
<< false << QStringLiteral("1234")
<< QStringList {
QStringLiteral("-kb"),
QStringLiteral("-p-"),
QStringLiteral("e"),
QStringLiteral("-p1234"),
QStringLiteral("-apaDir"),
QStringLiteral("/tmp/foo.rar"),
QStringLiteral("aDir/b.txt"),
QStringLiteral("c.txt"),
};
QTest::newRow("without paths, unencrypted, root node")
QTest::newRow("without paths, unencrypted")
<< QStringLiteral("/tmp/foo.rar")
<< QVariantList {
QVariant::fromValue(fileRootNodePair(QStringLiteral("aDir/b.txt"), QStringLiteral("aDir"))),
QVariant::fromValue(fileRootNodePair(QStringLiteral("c.txt"), QString()))
}
<< false << QString() << QStringLiteral("aDir")
<< false << QString()
<< QStringList {
QStringLiteral("-kb"),
QStringLiteral("-p-"),
QStringLiteral("e"),
QStringLiteral("-apaDir"),
QStringLiteral("/tmp/foo.rar"),
QStringLiteral("aDir/b.txt"),
QStringLiteral("c.txt"),
......@@ -413,16 +408,14 @@ void CliRarTest::testExtractArgs()
QStringLiteral("-p-"),
QStringLiteral("$PreservePathSwitch"),
QStringLiteral("$PasswordSwitch"),
QStringLiteral("$RootNodeSwitch"),
QStringLiteral("$Archive"),
QStringLiteral("$Files") };
QFETCH(QVariantList, files);
QFETCH(bool, preservePaths);
QFETCH(QString, password);
QFETCH(QString, rootNode);
QStringList replacedArgs = rarPlugin->substituteCopyVariables(extractArgs, files, preservePaths, password, rootNode);
QStringList replacedArgs = rarPlugin->substituteCopyVariables(extractArgs, files, preservePaths, password);
QVERIFY(replacedArgs.size() >= extractArgs.size());
QFETCH(QStringList, expectedArgs);
......
......@@ -374,7 +374,7 @@ void CliUnarchiverTest::testExtractArgs()
QFETCH(QVariantList, files);
QFETCH(QString, password);
QStringList replacedArgs = plugin->substituteCopyVariables(extractArgs, files, false, password, QString());
QStringList replacedArgs = plugin->substituteCopyVariables(extractArgs, files, false, password);
QVERIFY(replacedArgs.size() >= extractArgs.size());
QFETCH(QStringList, expectedArgs);
......
......@@ -194,7 +194,7 @@ void CliZipTest::testExtractArgs()
QFETCH(bool, preservePaths);
QFETCH(QString, password);
QStringList replacedArgs = plugin->substituteCopyVariables(extractArgs, files, preservePaths, password, QString());
QStringList replacedArgs = plugin->substituteCopyVariables(extractArgs, files, preservePaths, password);
QFETCH(QStringList, expectedArgs);
QCOMPARE(replacedArgs, expectedArgs);
......
......@@ -133,8 +133,7 @@ bool CliInterface::copyFiles(const QVariantList &files, const QString &destinati
const QStringList args = substituteCopyVariables(extractArgs,
files,
options.value(QStringLiteral("PreservePaths")).toBool(),
password(),
options.value(QStringLiteral("RootNode"), QString()).toString());
password());
QUrl destDir = QUrl(destinationDirectory);
QDir::setCurrent(destDir.adjusted(QUrl::RemoveScheme).url());
......@@ -597,7 +596,7 @@ QStringList CliInterface::substituteListVariables(const QStringList &listArgs, c
return args;
}
QStringList CliInterface::substituteCopyVariables(const QStringList &extractArgs, const QVariantList &files, bool preservePaths, const QString &password, const QString &rootNode)
QStringList CliInterface::substituteCopyVariables(const QStringList &extractArgs, const QVariantList &files, bool preservePaths, const QString &password)
{
// Required if we call this function from unit tests.
cacheParameterList();
......@@ -621,11 +620,6 @@ QStringList CliInterface::substituteCopyVariables(const QStringList &extractArgs
continue;
}
if (arg == QLatin1String("$RootNodeSwitch")) {
args << rootNodeSwitch(rootNode);
continue;
}
if (arg == QLatin1String("$Files")) {
args << copyFilesList(files);
continue;
......@@ -833,26 +827,6 @@ QString CliInterface::compressionLevelSwitch(int level) const
return compLevelSwitch;
}
QStringList CliInterface::rootNodeSwitch(const QString &rootNode) const
{
if (rootNode.isEmpty()) {
return QStringList();
}
Q_ASSERT(m_param.contains(RootNodeSwitch));
QStringList rootNodeSwitch = m_param.value(RootNodeSwitch).toStringList();
Q_ASSERT(!rootNodeSwitch.isEmpty() && rootNodeSwitch.size() <= 2);
if (rootNodeSwitch.size() == 1) {
rootNodeSwitch[0].replace(QLatin1String("$Path"), rootNode);
} else {
rootNodeSwitch[1] = rootNode;
}
return rootNodeSwitch;
}
QStringList CliInterface::copyFilesList(const QVariantList& files) const
{
QStringList filesList;
......
......@@ -130,14 +130,6 @@ enum CliInterfaceParameters {
* stringlist ("--extractFull", "")
*/
PreservePathSwitch,
/**
* QStringList (default empty)
* The format of the root node switch. The variable $Path will be
* substituted for the path string.
* Example: ("--internalPath=$Path)
* or ("--path", "$Path")
*/
RootNodeSwitch,
/**
* QStringList (default empty)
* The format of the root node switch. The variable $Password will be
......@@ -320,7 +312,7 @@ public:
bool moveToDestination(const QDir &tempDir, const QDir &destDir, bool preservePaths);
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 substituteCopyVariables(const QStringList &extractArgs, const QVariantList &files, bool preservePaths, const QString &password);
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);
......@@ -346,11 +338,6 @@ public:
*/
QString compressionLevelSwitch(int level) const;
/**
* @return The root node switch with the given @p rootNode.
*/
QStringList rootNodeSwitch(const QString& rootNode) const;
/**
* @return The list of selected files to extract.
*/
......
......@@ -94,7 +94,6 @@ ParameterList CliPlugin::parameterList() const
<< QStringLiteral( "$Files" );
p[PreservePathSwitch] = QStringList() << QStringLiteral( "x" )
<< QStringLiteral( "e" );
p[RootNodeSwitch] = QStringList() << QStringLiteral( "-ap$Path" );
p[PasswordSwitch] = QStringList() << QStringLiteral( "-p$Password" );
p[PasswordHeaderSwitch] = QStringList() << QStringLiteral("-hp$Password");
p[CompressionLevelSwitch] = QStringLiteral("-m$CompressionLevel");
......
......@@ -155,12 +155,6 @@ bool LibarchivePlugin::copyFiles(const QVariantList& files, const QString& desti
const bool preservePaths = options.value(QStringLiteral( "PreservePaths" )).toBool();
bool removeRootNode = options.value(QStringLiteral("RemoveRootNode"), QVariant()).toBool();
// See if there is a singular RootNode.
QString rootNodeSingular = options.value(QStringLiteral("RootNode"), QVariant()).toString();
if (!rootNodeSingular.isEmpty() && !rootNodeSingular.endsWith(QLatin1Char('/'))) {
rootNodeSingular.append(QLatin1Char('/'));
}
// To avoid traversing the entire archive when extracting a limited set of
// entries, we maintain a list of remaining entries and stop when it's
// empty.
......@@ -299,17 +293,6 @@ bool LibarchivePlugin::copyFiles(const QVariantList& files, const QString& desti
const QString truncatedFilename(entryName.remove(0, files.at(index).value<fileRootNodePair>().rootNode.size()));
archive_entry_copy_pathname(entry, QFile::encodeName(truncatedFilename).constData());
entryFI = QFileInfo(truncatedFilename);
// OR, if a singular rootNode is provided, remove it from file path.
} else if (removeRootNode &&
entryName != fileBeingRenamed &&
!rootNodeSingular.isEmpty()) {
//qCDebug(ARK) << "Removing" << rootNodeSingular << "from" << entryName;
const QString truncatedFilename(entryName.remove(0, rootNodeSingular.size()));
archive_entry_copy_pathname(entry, QFile::encodeName(truncatedFilename).constData());
entryFI = QFileInfo(truncatedFilename);
}
// Check if the file about to be written already exists.
......
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