From 118f713eb45387ead9a7bb076451ec33e7d5ca03 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 4 Apr 2019 16:18:20 +0200 Subject: [PATCH] Utils: Make Environment::isSameExecutable also detect hard links Change-Id: I64041a60febf9f5724028c488b535c5ec7b1f6a0 Reviewed-by: hjk --- src/libs/utils/environment.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp index a82d6c27f02..78629d71611 100644 --- a/src/libs/utils/environment.cpp +++ b/src/libs/utils/environment.cpp @@ -34,6 +34,12 @@ #include #include +#ifdef Q_OS_UNIX +#include +#include +#include +#endif + Q_GLOBAL_STATIC_WITH_ARGS(Utils::Environment, staticSystemEnvironment, (QProcessEnvironment::systemEnvironment().toStringList())) @@ -429,6 +435,21 @@ QStringList Environment::appendExeExtensions(const QString &executable) const 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 { const QStringList exe1List = appendExeExtensions(exe1); @@ -441,6 +462,8 @@ bool Environment::isSameExecutable(const QString &exe1, const QString &exe2) con return true; if (FileUtils::resolveSymlinks(f1) == FileUtils::resolveSymlinks(f2)) return true; + if (hasSameInode(f1.toString(), f2.toString())) + return true; } } return false;