forked from qt-creator/qt-creator
Utils: Introduce FilePath::mapTo{Device,Global}Path
Re-directing via IDevice::mapTo{Device,Global}Path Change-Id: Ica957839479967790bbd93e90eced66aa0b122a8 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -819,6 +819,24 @@ FilePath FilePath::symLinkTarget() const
|
|||||||
return FilePath::fromString(info.symLinkTarget());
|
return FilePath::fromString(info.symLinkTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePath FilePath::mapToGlobalPath() const
|
||||||
|
{
|
||||||
|
if (needsDevice()) {
|
||||||
|
QTC_ASSERT(s_deviceHooks.mapToGlobalPath, return {});
|
||||||
|
return s_deviceHooks.mapToGlobalPath(*this);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FilePath::mapToDevicePath() const
|
||||||
|
{
|
||||||
|
if (needsDevice()) {
|
||||||
|
QTC_ASSERT(s_deviceHooks.mapToDevicePath, return {});
|
||||||
|
return s_deviceHooks.mapToDevicePath(*this);
|
||||||
|
}
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
|
||||||
FilePath FilePath::withExecutableSuffix() const
|
FilePath FilePath::withExecutableSuffix() const
|
||||||
{
|
{
|
||||||
FilePath res = *this;
|
FilePath res = *this;
|
||||||
|
@@ -161,6 +161,9 @@ public:
|
|||||||
QDir::Filters filters = QDir::NoFilter,
|
QDir::Filters filters = QDir::NoFilter,
|
||||||
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) const;
|
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) const;
|
||||||
|
|
||||||
|
[[nodiscard]] FilePath mapToGlobalPath() const;
|
||||||
|
[[nodiscard]] QString mapToDevicePath() const;
|
||||||
|
|
||||||
// makes sure that capitalization of directories is canonical
|
// makes sure that capitalization of directories is canonical
|
||||||
// on Windows and macOS. This is rarely needed.
|
// on Windows and macOS. This is rarely needed.
|
||||||
[[nodiscard]] FilePath normalizedPathName() const;
|
[[nodiscard]] FilePath normalizedPathName() const;
|
||||||
|
@@ -78,6 +78,8 @@ public:
|
|||||||
std::function<bool(const FilePath &, const FilePath &)> renameFile;
|
std::function<bool(const FilePath &, const FilePath &)> renameFile;
|
||||||
std::function<FilePath(const FilePath &, const QList<FilePath> &)> searchInPath;
|
std::function<FilePath(const FilePath &, const QList<FilePath> &)> searchInPath;
|
||||||
std::function<FilePath(const FilePath &)> symLinkTarget;
|
std::function<FilePath(const FilePath &)> symLinkTarget;
|
||||||
|
std::function<FilePath(const FilePath &)> mapToGlobalPath;
|
||||||
|
std::function<QString(const FilePath &)> mapToDevicePath;
|
||||||
std::function<QList<FilePath>(const FilePath &, const QStringList &,
|
std::function<QList<FilePath>(const FilePath &, const QStringList &,
|
||||||
QDir::Filters, QDir::SortFlags)> dirEntries;
|
QDir::Filters, QDir::SortFlags)> dirEntries;
|
||||||
std::function<QByteArray(const FilePath &, qint64, qint64)> fileContents;
|
std::function<QByteArray(const FilePath &, qint64, qint64)> fileContents;
|
||||||
|
@@ -1069,6 +1069,17 @@ FilePath DockerDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DockerDevice::mapToDevicePath(const Utils::FilePath &globalPath) const
|
||||||
|
{
|
||||||
|
const FilePath normalized = globalPath.normalizedPathName();
|
||||||
|
QString path = normalized.path();
|
||||||
|
if (normalized.startsWithDriveLetter()) {
|
||||||
|
const QChar lowerDriveLetter = path.at(0).toLower();
|
||||||
|
path = '/' + lowerDriveLetter + path.mid(2); // strip C:
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
bool DockerDevice::handlesFile(const FilePath &filePath) const
|
bool DockerDevice::handlesFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
return filePath.scheme() == "docker" && filePath.host() == d->m_data.imageId;
|
return filePath.scheme() == "docker" && filePath.host() == d->m_data.imageId;
|
||||||
|
@@ -76,6 +76,7 @@ public:
|
|||||||
ProjectExplorer::DeviceEnvironmentFetcher::Ptr environmentFetcher() const override;
|
ProjectExplorer::DeviceEnvironmentFetcher::Ptr environmentFetcher() const override;
|
||||||
|
|
||||||
Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const override;
|
Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const override;
|
||||||
|
QString mapToDevicePath(const Utils::FilePath &globalPath) const override;
|
||||||
|
|
||||||
bool handlesFile(const Utils::FilePath &filePath) const override;
|
bool handlesFile(const Utils::FilePath &filePath) const override;
|
||||||
bool isExecutableFile(const Utils::FilePath &filePath) const override;
|
bool isExecutableFile(const Utils::FilePath &filePath) const override;
|
||||||
|
@@ -484,6 +484,18 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
|||||||
return device->symLinkTarget(filePath);
|
return device->symLinkTarget(filePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
deviceHooks.mapToGlobalPath = [](const FilePath &filePath) {
|
||||||
|
auto device = DeviceManager::deviceForPath(filePath);
|
||||||
|
QTC_ASSERT(device, return FilePath{});
|
||||||
|
return device->mapToGlobalPath(filePath);
|
||||||
|
};
|
||||||
|
|
||||||
|
deviceHooks.mapToDevicePath = [](const FilePath &filePath) {
|
||||||
|
auto device = DeviceManager::deviceForPath(filePath);
|
||||||
|
QTC_ASSERT(device, return QString{});
|
||||||
|
return device->mapToDevicePath(filePath);
|
||||||
|
};
|
||||||
|
|
||||||
deviceHooks.dirEntries = [](const FilePath &filePath, const QStringList &nameFilters,
|
deviceHooks.dirEntries = [](const FilePath &filePath, const QStringList &nameFilters,
|
||||||
QDir::Filters filters, QDir::SortFlags sort) {
|
QDir::Filters filters, QDir::SortFlags sort) {
|
||||||
auto device = DeviceManager::deviceForPath(filePath);
|
auto device = DeviceManager::deviceForPath(filePath);
|
||||||
|
@@ -212,6 +212,11 @@ FilePath IDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
|
|||||||
return pathOnDevice;
|
return pathOnDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString IDevice::mapToDevicePath(const FilePath &globalPath) const
|
||||||
|
{
|
||||||
|
return globalPath.path();
|
||||||
|
}
|
||||||
|
|
||||||
bool IDevice::handlesFile(const FilePath &filePath) const
|
bool IDevice::handlesFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(filePath);
|
Q_UNUSED(filePath);
|
||||||
|
@@ -237,6 +237,7 @@ public:
|
|||||||
bool isAnyUnixDevice() const;
|
bool isAnyUnixDevice() const;
|
||||||
|
|
||||||
virtual Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const;
|
virtual Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const;
|
||||||
|
virtual QString mapToDevicePath(const Utils::FilePath &globalPath) const;
|
||||||
|
|
||||||
virtual bool handlesFile(const Utils::FilePath &filePath) const;
|
virtual bool handlesFile(const Utils::FilePath &filePath) const;
|
||||||
virtual bool isExecutableFile(const Utils::FilePath &filePath) const;
|
virtual bool isExecutableFile(const Utils::FilePath &filePath) const;
|
||||||
|
Reference in New Issue
Block a user