From 23cf29ffddc560a023d6d714b8dfaae93b209432 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 10 Sep 2024 15:25:00 -0700 Subject: [PATCH] QFileSystemEngine/Win: only .lnk files that exist can be symlinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortunately, isDirPath() had an extra parameter to tell us whether the path existed in the first place, making the fix very simple. Pick-to: 6.7 6.5 Fixes: QTBUG-128800 Change-Id: I81482f87b594933158d0fffdbea0ea2a00494b6c Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Edward Welbourne (cherry picked from commit 329b05739d5d62f37464a5714ad87e7ca05693e2) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qfilesystemengine_win.cpp | 2 +- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index bdcac20dd32..89054a95bdf 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -1390,7 +1390,7 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM // Check for ".lnk": Directories named ".lnk" should be skipped, corrupted // link files should still be detected as links. const QString origFilePath = entry.filePath(); - if (origFilePath.endsWith(".lnk"_L1) && !isDirPath(origFilePath, nullptr)) { + if (bool exists; origFilePath.endsWith(".lnk"_L1) && !isDirPath(origFilePath, &exists) && exists) { data.entryFlags |= QFileSystemMetaData::WinLnkType; fname = QFileSystemEntry(readLink(entry)); } else { diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index fbc21d7a05d..7b31e2789b0 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1289,6 +1289,7 @@ void tst_QFileInfo::isSymLink_data() QTest::newRow("existent file") << m_sourceFile << false << ""; QTest::newRow("link") << "link.lnk" << true << QFileInfo(m_sourceFile).absoluteFilePath(); QTest::newRow("broken link") << "brokenlink.lnk" << true << QFileInfo("dummyfile").absoluteFilePath(); + QTest::newRow("nonexistent") << "thispathdoesntexist.lnk" << false << QString(); #ifndef Q_OS_WIN QDir::current().mkdir("relative"); @@ -1414,6 +1415,8 @@ void tst_QFileInfo::isSymbolicLink_data() << regularFile.fileName() << false; QTest::newRow("directory") << QDir::currentPath() << false; + QTest::newRow("nonexistent") + << "thispathdoesntexist.lnk" << false; #ifndef Q_NO_SYMLINKS #if defined(Q_OS_WIN)