summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemengine_unix.cpp
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2017-08-26 23:02:07 +0300
committerOrgad Shaneh <orgads@gmail.com>2017-08-27 02:39:57 +0000
commit0f11fab6f75dec78d3721280971448cc2edd6e72 (patch)
tree648bc7d7486039b2ceaaa61b0798b503709fa1b8 /src/corelib/io/qfilesystemengine_unix.cpp
parente51dbda0677d9ff4419c9dc70e6209fae194ee02 (diff)
Fix resolution of relative symlinks from relative path on unix
Consider the following: /root/target - a file /root/path/link -> ../target /root/path/other/exe - executable Running from /root/path/other. exe is: #include <QDebug> #include <QFileInfo> int main() { qDebug() << QFileInfo("../link").symLinkTarget() return 0; } The link references /root/target, but the current output is /root/path/target. The link doesn't depend on the PWD. It depends on its own directory. Change-Id: I61e95018154a75e0e0d795ee801068e18870a5df Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp12
1 files changed, 5 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('/')))