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)