diff options
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 12 | ||||
-rw-r--r-- | tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 7 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index ac0c43d055..7600c9a613 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -187,13 +187,11 @@ QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, #endif if (!ret.startsWith(QLatin1Char('/'))) { - const QString linkFilePath = link.filePath(); - if (linkFilePath.startsWith(QLatin1Char('/'))) { - ret.prepend(linkFilePath.leftRef(linkFilePath.lastIndexOf(QLatin1Char('/'))) - + QLatin1Char('/')); - } else { - ret.prepend(QDir::currentPath() + QLatin1Char('/')); - } + const QString linkPath = link.path(); + if (linkPath.startsWith(QLatin1Char('/'))) + ret.prepend(linkPath + QLatin1Char('/')); + else + ret.prepend(QDir::currentPath() + QLatin1Char('/') + linkPath + QLatin1Char('/')); } ret = QDir::cleanPath(ret); if (ret.size() > 1 && ret.endsWith(QLatin1Char('/'))) diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 87b579bb2b..17f41cba2b 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1261,6 +1261,7 @@ void tst_QFileInfo::isSymLink_data() QFile::remove("link.lnk"); QFile::remove("brokenlink.lnk"); QFile::remove("dummyfile"); + QFile::remove("relative/link.lnk"); QFile file1(m_sourceFile); QVERIFY(file1.link("link.lnk")); @@ -1277,6 +1278,12 @@ 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(); + +#ifndef Q_OS_WIN + QDir::current().mkdir("relative"); + QFile::link("../dummyfile", "relative/link.lnk"); + QTest::newRow("relative link") << "relative/link.lnk" << true << QFileInfo("dummyfile").absoluteFilePath(); +#endif #endif } |