Utils: Implement FilePath::withExecutableSuffix()

Change-Id: Ibf6919991b229eb91953b3c5b5cbb75a1be7ff5d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-06-29 16:57:16 +02:00
parent 28abf32b30
commit a2790ac95b
3 changed files with 22 additions and 0 deletions

View File

@@ -29,6 +29,7 @@
#include "algorithm.h"
#include "commandline.h"
#include "environment.h"
#include "hostosinfo.h"
#include "qtcassert.h"
#include <QDataStream>
@@ -1015,6 +1016,19 @@ FilePath FilePath::symLinkTarget() const
return FilePath::fromString(info.symLinkTarget());
}
FilePath FilePath::withExecutableSuffix() const
{
OsType osType;
if (needsDevice()) {
QTC_ASSERT(s_deviceHooks.osType, return {});
osType = s_deviceHooks.osType(*this);
} else {
osType = HostOsInfo::hostOs();
}
FilePath res = *this;
res.setPath(OsSpecificAspects::withExecutableSuffix(osType, m_data));
return res;
}
/// Find the parent directory of a given directory.

View File

@@ -90,6 +90,7 @@ public:
std::function<bool(const FilePath &, const QByteArray &)> writeFileContents;
std::function<QDateTime(const FilePath &)> lastModified;
std::function<QFile::Permissions(const FilePath &)> permissions;
std::function<OsType(const FilePath &)> osType;
};
class QTCREATOR_UTILS_EXPORT FilePath
@@ -190,6 +191,7 @@ public:
FilePath canonicalPath() const;
FilePath symLinkTarget() const;
FilePath withExecutableSuffix() const;
FilePath operator/(const QString &str) const;

View File

@@ -496,6 +496,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
return device->permissions(filePath);
};
deviceHooks.osType = [](const FilePath &filePath) {
auto device = DeviceManager::deviceForPath(filePath);
QTC_ASSERT(device, return OsTypeOther);
return device->osType();
};
FilePath::setDeviceFileHooks(deviceHooks);
DeviceProcessHooks processHooks;