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);
|
const FilePath f2 = FilePath::fromString(i2);
|
||||||
if (f1 == f2)
|
if (f1 == f2)
|
||||||
return true;
|
return true;
|
||||||
if (FileUtils::resolveSymlinks(f1) == FileUtils::resolveSymlinks(f2))
|
if (f1.resolveSymlinks() == f2.resolveSymlinks())
|
||||||
return true;
|
return true;
|
||||||
if (FileUtils::fileId(f1) == FileUtils::fileId(f2))
|
if (FileUtils::fileId(f1) == FileUtils::fileId(f2))
|
||||||
return true;
|
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.
|
To resolve symlinks anywhere in the path, see canonicalPath.
|
||||||
Unlike QFileInfo::canonicalFilePath(), this function will still return the expected deepest
|
Unlike QFileInfo::canonicalFilePath(), this function will still return the expected deepest
|
||||||
target file even if the symlink is dangling.
|
target file even if the symlink is dangling.
|
||||||
@@ -233,15 +233,17 @@ Qt::CaseSensitivity FilePath::caseSensitivity() const
|
|||||||
|
|
||||||
Returns the symlink target file path.
|
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;
|
int links = 16;
|
||||||
while (links-- && f.isSymLink())
|
while (links--) {
|
||||||
f.setFile(f.dir(), f.symLinkTarget());
|
const FilePath target = current.symLinkTarget();
|
||||||
if (links <= 0)
|
if (target.isEmpty())
|
||||||
return FilePath();
|
return current;
|
||||||
return FilePath::fromString(f.filePath());
|
current = target;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -195,6 +195,7 @@ public:
|
|||||||
|
|
||||||
FilePath canonicalPath() const;
|
FilePath canonicalPath() const;
|
||||||
FilePath symLinkTarget() const;
|
FilePath symLinkTarget() const;
|
||||||
|
FilePath resolveSymlinks() const;
|
||||||
FilePath withExecutableSuffix() const;
|
FilePath withExecutableSuffix() const;
|
||||||
|
|
||||||
FilePath operator/(const QString &str) const;
|
FilePath operator/(const QString &str) const;
|
||||||
@@ -256,7 +257,6 @@ public:
|
|||||||
T &©Helper);
|
T &©Helper);
|
||||||
static bool copyIfDifferent(const FilePath &srcFilePath,
|
static bool copyIfDifferent(const FilePath &srcFilePath,
|
||||||
const FilePath &tgtFilePath);
|
const FilePath &tgtFilePath);
|
||||||
static FilePath resolveSymlinks(const FilePath &path);
|
|
||||||
static QString fileSystemFriendlyName(const QString &name);
|
static QString fileSystemFriendlyName(const QString &name);
|
||||||
static int indexOfQmakeUnfriendly(const QString &name, int startpos = 0);
|
static int indexOfQmakeUnfriendly(const QString &name, int startpos = 0);
|
||||||
static QString qmakeFriendlyName(const QString &name);
|
static QString qmakeFriendlyName(const QString &name);
|
||||||
|
@@ -118,8 +118,7 @@ bool SaveFile::commit()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString finalFileName
|
QString finalFileName = FilePath::fromString(m_finalFileName).resolveSymlinks().toString();
|
||||||
= FileUtils::resolveSymlinks(FilePath::fromString(m_finalFileName)).toString();
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// Release the file lock
|
// Release the file lock
|
||||||
|
Reference in New Issue
Block a user