summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <[email protected]>2016-07-21 12:11:44 +0200
committerElvis Angelaccio <[email protected]>2016-07-21 12:11:44 +0200
commitc98d64bfb5176d03f37ae5bed9b1fe8d9d5bbbc2 (patch)
tree350fb3df3753e825acecadf797270839f8741934
parentbf2de67e185f042165cd17b8b8996fae0cc97381 (diff)
Fix extraction when an archive has a percentage in the name
QUrl::toDisplayString() results in a QString containing %25 instead of %. This affects both batch extractions and normal extractions from the Ark Part. Porting to QUrl::toLocalFile() fixes this issue. BUG: 365798 FIXED-IN: 16.08.0 Differential Revision: D2229
-rw-r--r--app/batchextract.cpp6
-rw-r--r--autotests/CMakeLists.txt1
-rw-r--r--autotests/app/CMakeLists.txt9
-rw-r--r--autotests/app/batchextracttest.cpp94
-rw-r--r--autotests/app/data/simple%archive.tar.gzbin0 -> 197 bytes
-rw-r--r--part/part.cpp2
6 files changed, 108 insertions, 4 deletions
diff --git a/app/batchextract.cpp b/app/batchextract.cpp
index 7c56f31..3534a41 100644
--- a/app/batchextract.cpp
+++ b/app/batchextract.cpp
@@ -213,12 +213,12 @@ void BatchExtract::forwardProgress(KJob *job, unsigned long percent)
bool BatchExtract::addInput(const QUrl& url)
{
- qCDebug(ARK) << "Adding archive" << url.toDisplayString(QUrl::PreferLocalFile);
+ qCDebug(ARK) << "Adding archive" << url.toLocalFile();
- Kerfuffle::Archive *archive = Kerfuffle::Archive::create(url.toDisplayString(QUrl::PreferLocalFile), this);
+ Kerfuffle::Archive *archive = Kerfuffle::Archive::create(url.toLocalFile(), this);
Q_ASSERT(archive);
- if (!QFileInfo::exists(url.toDisplayString(QUrl::PreferLocalFile))) {
+ if (!QFileInfo::exists(url.toLocalFile())) {
m_failedFiles.append(url.fileName());
return false;
}
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 4635d3b..71c7995 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -1,4 +1,5 @@
include(ECMAddTests)
+add_subdirectory(app)
add_subdirectory(kerfuffle)
add_subdirectory(plugins)
diff --git a/autotests/app/CMakeLists.txt b/autotests/app/CMakeLists.txt
new file mode 100644
index 0000000..10fb84a
--- /dev/null
+++ b/autotests/app/CMakeLists.txt
@@ -0,0 +1,9 @@
+include_directories(${CMAKE_SOURCE_DIR}/app)
+
+ecm_add_test(
+ batchextracttest.cpp
+ ${CMAKE_SOURCE_DIR}/app/batchextract.cpp
+ ${CMAKE_BINARY_DIR}/app/ark_debug.cpp
+ LINK_LIBRARIES Qt5::Test KF5::KIOFileWidgets kerfuffle
+ TEST_NAME batchextracttest
+ NAME_PREFIX app-)
diff --git a/autotests/app/batchextracttest.cpp b/autotests/app/batchextracttest.cpp
new file mode 100644
index 0000000..d49252e
--- /dev/null
+++ b/autotests/app/batchextracttest.cpp
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2016 Elvis Angelaccio <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "batchextract.h"
+
+#include <QDirIterator>
+#include <QTest>
+
+class BatchExtractTest : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testBatchExtraction_data();
+ void testBatchExtraction();
+};
+
+QTEST_GUILESS_MAIN(BatchExtractTest)
+
+void BatchExtractTest::testBatchExtraction_data()
+{
+ QTest::addColumn<QString>("archivePath");
+ QTest::addColumn<bool>("autoSubfolder");
+ QTest::addColumn<int>("expectedExtractedEntriesCount");
+
+ QString archivePath = QFINDTESTDATA("data/simple%archive.tar.gz");
+ QTest::newRow("extract the whole simple%archive.tar.gz (bug #365798)")
+ << archivePath
+ << true
+ << 4;
+}
+
+void BatchExtractTest::testBatchExtraction()
+{
+ auto batchJob = new BatchExtract(this);
+
+ QFETCH(QString, archivePath);
+ batchJob->addInput(QUrl::fromUserInput(archivePath));
+
+ QFETCH(bool, autoSubfolder);
+ batchJob->setAutoSubfolder(autoSubfolder);
+
+ QTemporaryDir destDir;
+ if (!destDir.isValid()) {
+ QSKIP("Could not create a temporary directory for extraction. Skipping test.", SkipSingle);
+ }
+
+ batchJob->setDestinationFolder(destDir.path());
+
+ QEventLoop eventLoop(this);
+ connect(batchJob, &KJob::result, &eventLoop, &QEventLoop::quit);
+ batchJob->start();
+ eventLoop.exec(); // krazy:exclude=crashy
+
+ QFETCH(int, expectedExtractedEntriesCount);
+ int extractedEntriesCount = 0;
+
+ QDirIterator dirIt(destDir.path(), QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
+ while (dirIt.hasNext()) {
+ extractedEntriesCount++;
+ dirIt.next();
+ }
+
+ if (autoSubfolder) {
+ // Also take into account the automatically created subfolder.
+ QCOMPARE(extractedEntriesCount, expectedExtractedEntriesCount + 1);
+ } else {
+ QCOMPARE(extractedEntriesCount, expectedExtractedEntriesCount);
+ }
+}
+
+#include "batchextracttest.moc"
diff --git a/autotests/app/data/simple%archive.tar.gz b/autotests/app/data/simple%archive.tar.gz
new file mode 100644
index 0000000..382144c
--- /dev/null
+++ b/autotests/app/data/simple%archive.tar.gz
Binary files differ
diff --git a/part/part.cpp b/part/part.cpp
index b678410..ee83b8c 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -1075,7 +1075,7 @@ void Part::slotShowExtractionDialog()
}
options[QStringLiteral("FollowExtractionDialogSettings")] = true;
- const QString destinationDirectory = dialog.data()->destinationDirectory().toDisplayString(QUrl::PreferLocalFile);
+ const QString destinationDirectory = dialog.data()->destinationDirectory().toLocalFile();
ExtractJob *job = m_model->extractFiles(files, destinationDirectory, options);
registerJob(job);