diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2021-10-26 19:19:47 +0300 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2021-12-09 13:44:24 +0200 |
commit | 8487987c0c32c06fb6dfc225a1ba347894215fb1 (patch) | |
tree | 91221cec6168b3f574ca2fe70d869e1c97661027 /src/libs | |
parent | 5f0df8562132dfc77dbdb352712e6d42efc35122 (diff) |
Enable handling 7z archives with libarchive
Make libarchive the default handler for 7z archives if the IFW
tools were built with the 'libarchive' configuration feature.
The LZMA SDK library is still built and can be used instead
if the config feature is omitted.
Also modify tests.
Task-number: QTIFW-2375
Change-Id: I1091d5fa140cbd783cddecc595f35c6562639b07
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/installer/archivefactory.cpp | 13 | ||||
-rw-r--r-- | src/libs/installer/createlocalrepositoryoperation.cpp | 14 | ||||
-rw-r--r-- | src/libs/installer/libarchivearchive.cpp | 3 | ||||
-rw-r--r-- | src/libs/installer/libarchivewrapper_p.cpp | 5 | ||||
-rw-r--r-- | src/libs/installer/libarchivewrapper_p.h | 1 | ||||
-rw-r--r-- | src/libs/installer/metadatajob_p.h | 16 |
6 files changed, 33 insertions, 19 deletions
diff --git a/src/libs/installer/archivefactory.cpp b/src/libs/installer/archivefactory.cpp index a946f9416..a7e55bd44 100644 --- a/src/libs/installer/archivefactory.cpp +++ b/src/libs/installer/archivefactory.cpp @@ -27,9 +27,10 @@ **************************************************************************/ #include "archivefactory.h" -#include "lib7zarchive.h" #ifdef IFW_LIBARCHIVE #include "libarchivewrapper.h" +#else +#include "lib7zarchive.h" #endif #include <QFileInfo> @@ -50,7 +51,8 @@ using namespace QInstaller; of this class can be created and its reference can be fetched from the \c {instance()} method. - The following archive handlers are registered by default: + Depending of the configuration features set at build time, one of the + following archive handlers is registered by default: \list \li Lib7z \li LibArchive @@ -137,11 +139,12 @@ bool ArchiveFactory::isSupportedType(const QString &filename) */ ArchiveFactory::ArchiveFactory() { - registerArchive<Lib7zArchive>(QLatin1String("Lib7z"), QStringList() - << QLatin1String("7z")); #ifdef IFW_LIBARCHIVE registerArchive<LibArchiveWrapper>(QLatin1String("LibArchive"), QStringList() << QLatin1String("tar.gz") << QLatin1String("tar.bz2") - << QLatin1String("tar.xz") << QLatin1String("zip") ); + << QLatin1String("tar.xz") << QLatin1String("zip") << QLatin1String("7z")); +#else + registerArchive<Lib7zArchive>(QLatin1String("Lib7z"), QStringList() + << QLatin1String("7z")); #endif } diff --git a/src/libs/installer/createlocalrepositoryoperation.cpp b/src/libs/installer/createlocalrepositoryoperation.cpp index 576e4fa3d..7090f9a8b 100644 --- a/src/libs/installer/createlocalrepositoryoperation.cpp +++ b/src/libs/installer/createlocalrepositoryoperation.cpp @@ -34,7 +34,7 @@ #include "fileio.h" #include "fileutils.h" #include "copydirectoryoperation.h" -#include "lib7zarchive.h" +#include "archivefactory.h" #include "packagemanagercore.h" #include "productkeycheck.h" #include "constants.h" @@ -124,12 +124,16 @@ static QString createArchive(const QString repoPath, const QString &sourceDir, c QFile archive(repoPath + fileName); - Lib7zArchive archiveFile(archive.fileName()); - if (!(archiveFile.open(QIODevice::WriteOnly) && archiveFile.create(QStringList() << sourceDir))) { + QScopedPointer<AbstractArchive> archiveFile(ArchiveFactory::instance().create(archive.fileName())); + if (!archiveFile) { + throw Error(CreateLocalRepositoryOperation::tr("Unsupported archive \"%1\": no handler " + "registered for file suffix \"%2\".").arg(archive.fileName(), QFileInfo(archive.fileName()).suffix())); + } + if (!(archiveFile->open(QIODevice::WriteOnly) && archiveFile->create(QStringList() << sourceDir))) { throw Error(CreateLocalRepositoryOperation::tr("Cannot create archive \"%1\": %2") - .arg(QDir::toNativeSeparators(archive.fileName()), archiveFile.errorString())); + .arg(QDir::toNativeSeparators(archive.fileName()), archiveFile->errorString())); } - archiveFile.close(); + archiveFile->close(); removeFiles(sourceDir, helper); // cleanup the files we compressed if (!archive.rename(sourceDir + fileName)) { throw Error(CreateLocalRepositoryOperation::tr("Cannot move file \"%1\" to \"%2\": %3") diff --git a/src/libs/installer/libarchivearchive.cpp b/src/libs/installer/libarchivearchive.cpp index 0e29be205..cf6e11e32 100644 --- a/src/libs/installer/libarchivearchive.cpp +++ b/src/libs/installer/libarchivearchive.cpp @@ -705,6 +705,7 @@ void LibArchiveArchive::configureReader(archive *archive) archive_read_support_format_tar(archive); archive_read_support_format_zip(archive); + archive_read_support_format_7zip(archive); } /*! @@ -714,6 +715,8 @@ void LibArchiveArchive::configureWriter(archive *archive) { if (QFileInfo(m_data->file.fileName()).suffix() == QLatin1String("zip")) { archive_write_set_format_zip(archive); + } else if (QFileInfo(m_data->file.fileName()).suffix() == QLatin1String("7z")) { + archive_write_set_format_7zip(archive); } else { archive_write_set_format_pax_restricted(archive); archive_write_set_format_filter_by_ext(archive, m_data->file.fileName().toLatin1()); diff --git a/src/libs/installer/libarchivewrapper_p.cpp b/src/libs/installer/libarchivewrapper_p.cpp index 30f81554a..e5c1e8598 100644 --- a/src/libs/installer/libarchivewrapper_p.cpp +++ b/src/libs/installer/libarchivewrapper_p.cpp @@ -138,13 +138,14 @@ QString LibArchiveWrapperPrivate::errorString() const */ bool LibArchiveWrapperPrivate::extract(const QString &dirPath, const quint64 totalFiles) { + const quint64 total = totalFiles ? totalFiles : m_archive.totalFiles(); if (connectToServer()) { QTimer timer; connect(&timer, &QTimer::timeout, this, &LibArchiveWrapperPrivate::processSignals); timer.start(); m_lock.lockForWrite(); - callRemoteMethod(QLatin1String(Protocol::AbstractArchiveExtract), dirPath, totalFiles); + callRemoteMethod(QLatin1String(Protocol::AbstractArchiveExtract), dirPath, total); m_lock.unlock(); { QEventLoop loop; @@ -154,7 +155,7 @@ bool LibArchiveWrapperPrivate::extract(const QString &dirPath, const quint64 tot timer.stop(); return (workerStatus() == ExtractWorker::Success); } - return m_archive.extract(dirPath, totalFiles); + return m_archive.extract(dirPath, total); } /*! diff --git a/src/libs/installer/libarchivewrapper_p.h b/src/libs/installer/libarchivewrapper_p.h index 4277cd4f9..9e612fab3 100644 --- a/src/libs/installer/libarchivewrapper_p.h +++ b/src/libs/installer/libarchivewrapper_p.h @@ -32,7 +32,6 @@ #include "installer_global.h" #include "remoteobject.h" #include "libarchivearchive.h" -#include "lib7zarchive.h" #include <QTimer> #include <QReadWriteLock> diff --git a/src/libs/installer/metadatajob_p.h b/src/libs/installer/metadatajob_p.h index 99b48e626..d2922babd 100644 --- a/src/libs/installer/metadatajob_p.h +++ b/src/libs/installer/metadatajob_p.h @@ -29,7 +29,7 @@ #ifndef METADATAJOB_P_H #define METADATAJOB_P_H -#include "lib7zarchive.h" +#include "archivefactory.h" #include "metadatajob.h" #include <QDir> @@ -75,14 +75,18 @@ public: return; // ignore already canceled } - Lib7zArchive archive(m_archive); - if (!archive.open(QIODevice::ReadOnly)) { + QScopedPointer<AbstractArchive> archive(ArchiveFactory::instance().create(m_archive)); + 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)) { fi.reportException(UnzipArchiveException(MetadataJob::tr("Cannot open file \"%1\" for " - "reading: %2").arg(QDir::toNativeSeparators(m_archive), archive.errorString()))); + "reading: %2").arg(QDir::toNativeSeparators(m_archive), archive->errorString()))); } - if (!archive.extract(m_targetDir)) { + if (!archive->extract(m_targetDir)) { fi.reportException(UnzipArchiveException(MetadataJob::tr("Error while extracting " - "archive \"%1\": %2").arg(QDir::toNativeSeparators(m_archive), archive.errorString()))); + "archive \"%1\": %2").arg(QDir::toNativeSeparators(m_archive), archive->errorString()))); } fi.reportFinished(); |