summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2021-10-28 12:32:54 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2021-10-29 09:56:08 +0300
commit6cd1ff494d4d7aadc12204789407679aa065b4a6 (patch)
treec438c330025fab6c601dc693328e157e24cf59bc
parent002b2e15d05a1a6784595855408c331531f03746 (diff)
Fix creating archives containing Windows shortcuts
On Windows, QFileInfo::isSymLink() returns true for *.lnk files, which unlike symlinks contain data - when creating an archive the writing was incorrectly skipped. Also add test case for creating and extracting archives containing either symlinks or shortcuts. Change-Id: I3ebbd28e889ffa17ece7378c3812244a55df20d5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r--src/libs/installer/libarchivearchive.cpp2
-rw-r--r--tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp56
2 files changed, 57 insertions, 1 deletions
diff --git a/src/libs/installer/libarchivearchive.cpp b/src/libs/installer/libarchivearchive.cpp
index 4147214a8..46200560b 100644
--- a/src/libs/installer/libarchivearchive.cpp
+++ b/src/libs/installer/libarchivearchive.cpp
@@ -500,7 +500,7 @@ bool LibArchiveArchive::create(const QStringList &data)
if (status < ARCHIVE_OK)
throw Error(QLatin1String(archive_error_string(writer.get())));
- if (fileOrDir.isDir() || fileOrDir.isSymLink() || archive_entry_size(entry.get()) == 0)
+ if (fileOrDir.isDir() || archive_entry_size(entry.get()) == 0)
continue; // nothing to copy
QFile file(pathWithoutNamespace(QLatin1String(archive_entry_sourcepath(entry.get()))));
diff --git a/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp b/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp
index 8034f9556..a1f5a1994 100644
--- a/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp
+++ b/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp
@@ -26,6 +26,8 @@
**
**************************************************************************/
+#include "../shared/verifyinstaller.h"
+
#include <libarchivearchive.h>
#include <fileutils.h>
@@ -149,6 +151,60 @@ private slots:
QVERIFY(QFile(QDir::tempPath() + QString("/valid")).remove());
}
+ void testCreateExtractWithSymlink_data()
+ {
+ archiveSuffixesTestData();
+ }
+
+ void testCreateExtractWithSymlink()
+ {
+ QFETCH(QString, suffix);
+
+ const QString workingDir = generateTemporaryFileName() + "/";
+ const QString archiveName = workingDir + "archive" + suffix;
+ const QString targetName = workingDir + "target/";
+#ifdef Q_OS_WIN
+ const QString linkName = workingDir + "link.lnk";
+#else
+ const QString linkName = workingDir + "link";
+#endif
+
+ QVERIFY(QDir().mkpath(targetName));
+
+ QFile source(workingDir + "file");
+ QVERIFY(source.open(QIODevice::ReadWrite));
+ QVERIFY(source.write("Source File"));
+
+ // Creates a shortcut on Windows, a symbolic link on Unix
+ QVERIFY(QFile::link(source.fileName(), linkName));
+
+ LibArchiveArchive archive(archiveName);
+ QVERIFY(archive.open(QIODevice::ReadWrite));
+ QVERIFY(archive.create(QStringList() << source.fileName() << linkName));
+ QVERIFY(QFileInfo::exists(archiveName));
+
+ QVERIFY(archive.extract(targetName));
+ const QString sourceFilename = QFileInfo(source.fileName()).fileName();
+ const QString linkFilename = QFileInfo(linkName).fileName();
+ QVERIFY(QFileInfo::exists(targetName + sourceFilename));
+ QVERIFY(QFileInfo::exists(targetName + linkFilename));
+
+ VerifyInstaller::verifyFileContent(targetName + sourceFilename, source.readAll());
+ const QString sourceFilePath = workingDir + sourceFilename;
+ QCOMPARE(QFile::symLinkTarget(targetName + linkFilename), sourceFilePath);
+
+ archive.close();
+
+ QVERIFY(source.remove());
+ QVERIFY(QFile::remove(archiveName));
+ QVERIFY(QFile::remove(linkName));
+ QVERIFY(QFile::remove(targetName + sourceFilename));
+ QVERIFY(QFile::remove(targetName + linkFilename));
+
+ removeDirectory(targetName, true);
+ removeDirectory(workingDir, true);
+ }
+
private:
void archiveFilenamesTestData()
{