@@ -82,9 +82,6 @@ bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QString
8282 if ( zip_fread ( file, buf.get (), len ) != -1 )
8383 {
8484 QString fileName ( stat.name );
85- // remove leading `/` e.g. `/project.qgs` -> `project.qgs`
86- while ( fileName.startsWith ( QDir::separator () ) )
87- fileName.remove ( 0 , 1 );
8885 QFileInfo newFile ( QDir ( dir ), fileName );
8986
9087 // Create path for a new file if it does not exist.
@@ -132,7 +129,7 @@ bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QString
132129 return true ;
133130}
134131
135- bool QgsZipUtils::zip ( const QString &zipFilename, const QStringList &files, const QString &root )
132+ bool QgsZipUtils::zip ( const QString &zipFilename, const QStringList &files )
136133{
137134 if ( zipFilename.isEmpty () )
138135 {
@@ -156,22 +153,15 @@ bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files, con
156153 return false ;
157154 }
158155
159- const QByteArray filePathUtf8 = file.toUtf8 ();
160- zip_source *src = zip_source_file ( z, filePathUtf8 .constData (), 0 , 0 );
156+ const QByteArray fileNamePtr = file.toUtf8 ();
157+ zip_source *src = zip_source_file ( z, fileNamePtr .constData (), 0 , 0 );
161158 if ( src )
162159 {
163- QString fileName;
164- if ( root.isEmpty () || !file.startsWith ( root ) )
165- fileName = fileInfo.fileName ();
166- else
167- fileName = file.right ( file.length () - root.length () );
168-
169-
170- const QByteArray fileNameUtf8 = fileName.toUtf8 ();
160+ const QByteArray fileInfoPtr = fileInfo.fileName ().toUtf8 ();
171161#if LIBZIP_VERSION_MAJOR < 1
172- int rc = ( int ) zip_add ( z, fileNameUtf8 .constData (), src );
162+ int rc = ( int ) zip_add ( z, fileInfoPtr .constData (), src );
173163#else
174- int rc = ( int ) zip_file_add ( z, fileNameUtf8 .constData (), src, 0 );
164+ int rc = ( int ) zip_file_add ( z, fileInfoPtr .constData (), src, 0 );
175165#endif
176166 if ( rc == -1 )
177167 {
0 commit comments