forked from qt-creator/qt-creator
Utils: Move resolveSymLinks from FileUtils to FilePath
And make it work with remote paths. Change-Id: I1fe4548547231338284152a86c43f5d0b1eba4d6 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -183,7 +183,7 @@ bool Environment::isSameExecutable(const QString &exe1, const QString &exe2) con
|
||||
const FilePath f2 = FilePath::fromString(i2);
|
||||
if (f1 == f2)
|
||||
return true;
|
||||
if (FileUtils::resolveSymlinks(f1) == FileUtils::resolveSymlinks(f2))
|
||||
if (f1.resolveSymlinks() == f2.resolveSymlinks())
|
||||
return true;
|
||||
if (FileUtils::fileId(f1) == FileUtils::fileId(f2))
|
||||
return true;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@@ -195,6 +195,7 @@ public:
|
||||
|
||||
FilePath canonicalPath() const;
|
||||
FilePath symLinkTarget() const;
|
||||
FilePath resolveSymlinks() const;
|
||||
FilePath withExecutableSuffix() const;
|
||||
|
||||
FilePath operator/(const QString &str) const;
|
||||
@@ -256,7 +257,6 @@ public:
|
||||
T &©Helper);
|
||||
static bool copyIfDifferent(const FilePath &srcFilePath,
|
||||
const FilePath &tgtFilePath);
|
||||
static FilePath resolveSymlinks(const FilePath &path);
|
||||
static QString fileSystemFriendlyName(const QString &name);
|
||||
static int indexOfQmakeUnfriendly(const QString &name, int startpos = 0);
|
||||
static QString qmakeFriendlyName(const QString &name);
|
||||
|
@@ -118,8 +118,7 @@ bool SaveFile::commit()
|
||||
return false;
|
||||
}
|
||||
|
||||
QString finalFileName
|
||||
= FileUtils::resolveSymlinks(FilePath::fromString(m_finalFileName)).toString();
|
||||
QString finalFileName = FilePath::fromString(m_finalFileName).resolveSymlinks().toString();
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
// Release the file lock
|
||||
|
Reference in New Issue
Block a user