diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2021-10-28 12:32:54 +0300 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2021-10-29 09:56:08 +0300 |
commit | 6cd1ff494d4d7aadc12204789407679aa065b4a6 (patch) | |
tree | c438c330025fab6c601dc693328e157e24cf59bc /tests | |
parent | 002b2e15d05a1a6784595855408c331531f03746 (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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
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() { |