Skip to content

Commit

Permalink
[api] Add a new QgsZipUtils::unzip() parameter to skip consistency check
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and nyalldawson committed Mar 15, 2023
1 parent 838f399 commit 823b13f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion python/core/auto_generated/qgsziputils.sip.in
Expand Up @@ -25,12 +25,13 @@ extension, ``False`` otherwise.
:return: ``True`` if the file is zipped, ``False`` otherwise
%End

bool unzip( const QString &zip, const QString &dir, QStringList &files /Out/ );
bool unzip( const QString &zip, const QString &dir, QStringList &files /Out/, bool checkConsistency = true );
%Docstring
Unzip a zip file in an output directory.

:param zip: The zip filename
:param dir: The output directory
:param checkConsistency: Perform additional stricter consistency checks on the archive, and error if they fail (since QGIS 3.30)

:return: - ``False`` if the zip filename does not exist, the output directory
- files: The absolute path of unzipped files
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsziputils.cpp
Expand Up @@ -34,7 +34,7 @@ bool QgsZipUtils::isZipFile( const QString &filename )
return QFileInfo( filename ).suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) == 0;
}

bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QStringList &files )
bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QStringList &files, bool checkConsistency )
{
files.clear();

Expand Down Expand Up @@ -66,7 +66,7 @@ bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QString

int rc = 0;
const QByteArray fileNamePtr = zipFilename.toUtf8();
struct zip *z = zip_open( fileNamePtr.constData(), ZIP_CHECKCONS, &rc );
struct zip *z = zip_open( fileNamePtr.constData(), checkConsistency ? ZIP_CHECKCONS : 0, &rc );

if ( rc == ZIP_ER_OK && z )
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsziputils.h
Expand Up @@ -42,11 +42,12 @@ namespace QgsZipUtils
* \param zip The zip filename
* \param dir The output directory
* \param files The absolute path of unzipped files
* \param checkConsistency Perform additional stricter consistency checks on the archive, and error if they fail (since QGIS 3.30)
* \returns FALSE if the zip filename does not exist, the output directory
* does not exist or is not writable.
* \since QGIS 3.0
*/
CORE_EXPORT bool unzip( const QString &zip, const QString &dir, QStringList &files SIP_OUT );
CORE_EXPORT bool unzip( const QString &zip, const QString &dir, QStringList &files SIP_OUT, bool checkConsistency = true );

/**
* Zip the list of files in the zip file. If the zip file already exists or is
Expand Down

0 comments on commit 823b13f

Please sign in to comment.