forked from qt-creator/qt-creator
Utils: Make Environment::isSameExecutable also detect hard links
Change-Id: I64041a60febf9f5724028c488b535c5ec7b1f6a0 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -34,6 +34,12 @@
|
|||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(Utils::Environment, staticSystemEnvironment,
|
Q_GLOBAL_STATIC_WITH_ARGS(Utils::Environment, staticSystemEnvironment,
|
||||||
(QProcessEnvironment::systemEnvironment().toStringList()))
|
(QProcessEnvironment::systemEnvironment().toStringList()))
|
||||||
|
|
||||||
@@ -429,6 +435,21 @@ QStringList Environment::appendExeExtensions(const QString &executable) const
|
|||||||
return execs;
|
return execs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool hasSameInode(const QString &file1, const QString &file2)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
|
struct stat stat1;
|
||||||
|
if (stat(file1.toLocal8Bit().constData(), &stat1) < 0)
|
||||||
|
return false;
|
||||||
|
struct stat stat2;
|
||||||
|
if (stat(file2.toLocal8Bit().constData(), &stat2) < 0)
|
||||||
|
return false;
|
||||||
|
return stat1.st_ino == stat2.st_ino;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool Environment::isSameExecutable(const QString &exe1, const QString &exe2) const
|
bool Environment::isSameExecutable(const QString &exe1, const QString &exe2) const
|
||||||
{
|
{
|
||||||
const QStringList exe1List = appendExeExtensions(exe1);
|
const QStringList exe1List = appendExeExtensions(exe1);
|
||||||
@@ -441,6 +462,8 @@ bool Environment::isSameExecutable(const QString &exe1, const QString &exe2) con
|
|||||||
return true;
|
return true;
|
||||||
if (FileUtils::resolveSymlinks(f1) == FileUtils::resolveSymlinks(f2))
|
if (FileUtils::resolveSymlinks(f1) == FileUtils::resolveSymlinks(f2))
|
||||||
return true;
|
return true;
|
||||||
|
if (hasSameInode(f1.toString(), f2.toString()))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user