Qt: Fix zip import/export on Windows

On Windows, cleaning up the filename inside the zip
failed due to the backslash not properly being recognized.
This lead to profiles, which could not be imported on another
machine, if the filename contained a path not existing there.

Bug: 16608
Change-Id: Ib30b2370e30c30ac60f283edf6376c07258c25b6
Reviewed-on: https://code.wireshark.org/review/37437
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Roland Knall 2020-06-10 13:23:58 +02:00
parent 0d10d8e6e8
commit 6f700a9da6
1 changed files with 17 additions and 2 deletions

View File

@ -65,12 +65,26 @@ bool WiresharkZipHelper::unzip(QString zipFile, QString directory, bool (*fileCh
QString fileInZip(filename_inzip);
int fileSize = static_cast<int>(file_info.uncompressed_size);
/* Sanity check for the filen */
/* Sanity check for the file */
if (fileInZip.length() == 0 || (fileCheck && ! fileCheck(fileInZip, fileSize)) )
continue;
if (di.exists())
{
#ifdef _WIN32
/* This is an additional fix for bug 16608, in which exports did contain the full path they
* where exported from, leading to imports not possible if the path does not exist on that
* machine */
if (fileInZip.contains(":/") || fileInZip.contains(":\\"))
{
QFileInfo fileName(fileInZip);
QFileInfo path(fileName.dir(), "");
QString newFile = path.baseName() + "/" + fileName.baseName();
fileInZip = newFile;
}
#endif
QString fullPath = di.path() + "/" + fileInZip;
QFileInfo fi(fullPath);
QString dirPath = fi.absolutePath();
@ -232,7 +246,8 @@ bool WiresharkZipHelper::zip(QString fileName, QStringList files, QString relati
{
QFileInfo sf(files.at(cnt));
QString fileInZip = sf.absoluteFilePath();
fileInZip.replace(relativeTo, "");
QFileInfo relat(relativeTo);
fileInZip.replace(relat.absoluteFilePath(), "");
/* Windows cannot open zip files, if the filenames starts with a separator */
while (fileInZip.length() > 0 && fileInZip.startsWith("/"))
fileInZip = fileInZip.right(fileInZip.length() - 1);