aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/fileutils.cpp
diff options
context:
space:
mode:
authorhjk <[email protected]>2021-07-02 08:53:59 +0200
committerhjk <[email protected]>2021-07-02 11:08:00 +0000
commit2bf72a6dfd2aabf9ca2c6f6051f29fa00a1cce3b (patch)
tree1e22c39bdafe274e6ac77755065be0bc82d994bb /src/libs/utils/fileutils.cpp
parent943447aed3253a42385f0bb394a2ece839993c81 (diff)
Utils: Move resolveSymLinks from FileUtils to FilePath
And make it work with remote paths. Change-Id: I1fe4548547231338284152a86c43f5d0b1eba4d6 Reviewed-by: Christian Stenger <[email protected]>
Diffstat (limited to 'src/libs/utils/fileutils.cpp')
-rw-r--r--src/libs/utils/fileutils.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp
index 9e68b91853d..e44faa5e087 100644
--- a/src/libs/utils/fileutils.cpp
+++ b/src/libs/utils/fileutils.cpp
@@ -224,7 +224,7 @@ Qt::CaseSensitivity FilePath::caseSensitivity() const
}
/*!
- Recursively resolves symlinks if \a filePath is a symlink.
+ Recursively resolves symlinks if this is a symlink.
To resolve symlinks anywhere in the path, see canonicalPath.
Unlike QFileInfo::canonicalFilePath(), this function will still return the expected deepest
target file even if the symlink is dangling.
@@ -233,15 +233,17 @@ Qt::CaseSensitivity FilePath::caseSensitivity() const
Returns the symlink target file path.
*/
-FilePath FileUtils::resolveSymlinks(const FilePath &path)
+FilePath FilePath::resolveSymlinks() const
{
- QFileInfo f = path.toFileInfo();
+ FilePath current = *this;
int links = 16;
- while (links-- && f.isSymLink())
- f.setFile(f.dir(), f.symLinkTarget());
- if (links <= 0)
- return FilePath();
- return FilePath::fromString(f.filePath());
+ while (links--) {
+ const FilePath target = current.symLinkTarget();
+ if (target.isEmpty())
+ return current;
+ current = target;
+ }
+ return current;
}
/*!