summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-01-11 10:59:00 +0200
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-01-11 13:13:38 +0200
commit5ec5af811a9a4146f32378bbd80acfbb5a46f621 (patch)
treec4cb652d31af72b02f6287ad0b6101b695dc8aad
parent48a2499662fd1dc45f1dc87d5ff9e8956c7961b7 (diff)
ArchiveFactory: register handlers for .qbsp file extension
QBSP archives were missing a handler which caused UnzipArchiveTask to fail when fetching metadata. Also fix the resulted segfault in UnzipArchiveTask::doTask() when ArchiveFactory::create() returns nullptr for unknown file extension - it now handles the exception properly. Task-number: QTIFW-2475 Change-Id: I72624763a06d6e7495daebd69970a5f22a4fd6d3 Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r--src/libs/installer/archivefactory.cpp5
-rw-r--r--src/libs/installer/libarchivearchive.cpp8
-rw-r--r--src/libs/installer/metadatajob_p.h6
-rw-r--r--tests/auto/installer/archivefactory/tst_archivefactory.cpp4
-rw-r--r--tests/auto/installer/libarchivearchive/data.qrc1
-rw-r--r--tests/auto/installer/libarchivearchive/data/valid.qbspbin0 -> 950 bytes
-rw-r--r--tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp2
7 files changed, 17 insertions, 9 deletions
diff --git a/src/libs/installer/archivefactory.cpp b/src/libs/installer/archivefactory.cpp
index e6582cbcd..5bfabe943 100644
--- a/src/libs/installer/archivefactory.cpp
+++ b/src/libs/installer/archivefactory.cpp
@@ -142,9 +142,10 @@ ArchiveFactory::ArchiveFactory()
#ifdef IFW_LIBARCHIVE
registerArchive<LibArchiveWrapper>(QLatin1String("LibArchive"), QStringList()
<< QLatin1String("tar") << QLatin1String("tar.gz") << QLatin1String("tar.bz2")
- << QLatin1String("tar.xz") << QLatin1String("zip") << QLatin1String("7z"));
+ << QLatin1String("tar.xz") << QLatin1String("zip") << QLatin1String("7z")
+ << QLatin1String("qbsp"));
#else
registerArchive<Lib7zArchive>(QLatin1String("Lib7z"), QStringList()
- << QLatin1String("7z"));
+ << QLatin1String("7z") << QLatin1String("qbsp"));
#endif
}
diff --git a/src/libs/installer/libarchivearchive.cpp b/src/libs/installer/libarchivearchive.cpp
index 0f5b21a29..3ada73dd2 100644
--- a/src/libs/installer/libarchivearchive.cpp
+++ b/src/libs/installer/libarchivearchive.cpp
@@ -713,7 +713,13 @@ void LibArchiveArchive::configureReader(archive *archive)
*/
void LibArchiveArchive::configureWriter(archive *archive)
{
- archive_write_set_format_filter_by_ext(archive, m_data->file.fileName().toLatin1());
+ const QString fileName = m_data->file.fileName();
+ if (fileName.endsWith(QLatin1String(".qbsp"), Qt::CaseInsensitive)) {
+ // The Qt board support package file extension is really a 7z.
+ archive_write_set_format_7zip(archive);
+ } else {
+ archive_write_set_format_filter_by_ext(archive, fileName.toLatin1());
+ }
if (compressionLevel() == CompressionLevel::Normal)
return;
diff --git a/src/libs/installer/metadatajob_p.h b/src/libs/installer/metadatajob_p.h
index d2922babd..2511f4b00 100644
--- a/src/libs/installer/metadatajob_p.h
+++ b/src/libs/installer/metadatajob_p.h
@@ -79,12 +79,10 @@ public:
if (!archive) {
fi.reportException(UnzipArchiveException(MetadataJob::tr("Unsupported archive \"%1\": no handler "
"registered for file suffix \"%2\".").arg(m_archive, QFileInfo(m_archive).suffix())));
- }
- if (!archive->open(QIODevice::ReadOnly)) {
+ } else if (!archive->open(QIODevice::ReadOnly)) {
fi.reportException(UnzipArchiveException(MetadataJob::tr("Cannot open file \"%1\" for "
"reading: %2").arg(QDir::toNativeSeparators(m_archive), archive->errorString())));
- }
- if (!archive->extract(m_targetDir)) {
+ } else if (!archive->extract(m_targetDir)) {
fi.reportException(UnzipArchiveException(MetadataJob::tr("Error while extracting "
"archive \"%1\": %2").arg(QDir::toNativeSeparators(m_archive), archive->errorString())));
}
diff --git a/tests/auto/installer/archivefactory/tst_archivefactory.cpp b/tests/auto/installer/archivefactory/tst_archivefactory.cpp
index 91301898d..a00f8c815 100644
--- a/tests/auto/installer/archivefactory/tst_archivefactory.cpp
+++ b/tests/auto/installer/archivefactory/tst_archivefactory.cpp
@@ -90,10 +90,10 @@ private slots:
#ifdef IFW_LIBARCHIVE
QTest::newRow("LibArchive")
<< "LibArchive" << "myfile.zip"
- << (QStringList() << "tar" << "tar.gz" << "tar.bz2" << "tar.xz" << "zip" << "7z");
+ << (QStringList() << "tar" << "tar.gz" << "tar.bz2" << "tar.xz" << "zip" << "7z" << "qbsp");
#else
QTest::newRow("Lib7z")
- << "Lib7z" << "myfile.7z" << (QStringList() << "7z");
+ << "Lib7z" << "myfile.7z" << (QStringList() << "7z" << "qbsp");
#endif
}
diff --git a/tests/auto/installer/libarchivearchive/data.qrc b/tests/auto/installer/libarchivearchive/data.qrc
index dd9eb9090..b3f2a1933 100644
--- a/tests/auto/installer/libarchivearchive/data.qrc
+++ b/tests/auto/installer/libarchivearchive/data.qrc
@@ -5,5 +5,6 @@
<file>data/valid.tar.bz2</file>
<file>data/valid.tar.xz</file>
<file>data/valid.7z</file>
+ <file>data/valid.qbsp</file>
</qresource>
</RCC>
diff --git a/tests/auto/installer/libarchivearchive/data/valid.qbsp b/tests/auto/installer/libarchivearchive/data/valid.qbsp
new file mode 100644
index 000000000..e583bdf99
--- /dev/null
+++ b/tests/auto/installer/libarchivearchive/data/valid.qbsp
Binary files differ
diff --git a/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp b/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp
index 1af5023e1..57f16b762 100644
--- a/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp
+++ b/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp
@@ -246,6 +246,7 @@ private:
QTest::newRow("bzip2 compressed tar archive") << ":///data/valid.tar.bz2";
QTest::newRow("xz compressed tar archive") << ":///data/valid.tar.xz";
QTest::newRow("7zip archive") << ":///data/valid.7z";
+ QTest::newRow("QBSP archive (7z)") << ":///data/valid.qbsp";
}
void archiveSuffixesTestData()
@@ -257,6 +258,7 @@ private:
QTest::newRow("bzip2 compressed tar archive") << ".tar.bz2";
QTest::newRow("xz compressed tar archive") << ".tar.xz";
QTest::newRow("7z archive") << ".7z";
+ QTest::newRow("QBSP archive") << ".qbsp";
}
QString tempSourceFile(const QByteArray &data, const QString &templateName = QString())