From df859d891d303bef422dd97eed1db4a99e25cc43 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Fri, 16 Sep 2022 10:26:41 +0200 Subject: [PATCH] Filepath: Add ::isSameDevice Change-Id: I3990429b59759d5f72ed95e3a0d1723d3bb7bb82 Reviewed-by: hjk --- src/libs/utils/filepath.cpp | 11 +++++++++++ src/libs/utils/filepath.h | 4 ++++ src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp | 9 +-------- .../projectexplorer/devicesupport/devicemanager.cpp | 7 +++++++ .../projectexplorer/devicesupport/filetransfer.cpp | 7 +------ 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 1b478bb6d4a..eaa1922c089 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -614,6 +614,17 @@ bool FilePath::needsDevice() const return !m_scheme.isEmpty(); } +bool FilePath::isSameDevice(const FilePath &other) const +{ + if (needsDevice() != other.needsDevice()) + return false; + if (!needsDevice() && !other.needsDevice()) + return true; + + QTC_ASSERT(s_deviceHooks.isSameDevice, return true); + return s_deviceHooks.isSameDevice(*this, other); +} + /// \returns an empty FilePath if this is not a symbolic linl FilePath FilePath::symLinkTarget() const { diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 2a0e056f436..6857442e1f2 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -187,6 +187,8 @@ public: // on FilePath::osType(). bool needsDevice() const; + bool isSameDevice(const FilePath &other) const; + [[nodiscard]] QFileInfo toFileInfo() const; [[nodiscard]] static FilePath fromFileInfo(const QFileInfo &info); @@ -260,6 +262,8 @@ public: std::function fileSize; std::function bytesAvailable; std::function deviceDisplayName; + std::function isSameDevice; + template using Continuation = std::function; std::function &, const FilePath &, const FilePath &)> asyncCopyFile; diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index 83cc3273f18..43e354dbf09 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -864,14 +864,7 @@ void CMakeBuildSystem::ensureBuildDirectory(const BuildDirParameters ¶meters } if (tool->cmakeExecutable().needsDevice()) { - if (bdir.needsDevice()) { - if (bdir.scheme() != tool->cmakeExecutable().scheme() - || bdir.host() != tool->cmakeExecutable().host()) { - handleParsingFailed( - tr("The CMake executable and the build directory are not on the same device.")); - return; - } - } else if (!tool->cmakeExecutable().ensureReachable(bdir)) { + if (!tool->cmakeExecutable().ensureReachable(bdir)) { // Make sure that the build directory is available on the device. handleParsingFailed( tr("The remote CMake executable cannot write to the local build directory.")); diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index b1f7ad58d82..7a5c9c416a9 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -429,6 +429,13 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_uniqueisWritableDirectory(filePath); }; + deviceHooks.isSameDevice = [](const FilePath &left, const FilePath &right) { + auto leftDevice = DeviceManager::deviceForPath(left); + auto rightDevice = DeviceManager::deviceForPath(right); + + return leftDevice == rightDevice; + }; + deviceHooks.isWritableFile = [](const FilePath &filePath) { auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return false); diff --git a/src/plugins/projectexplorer/devicesupport/filetransfer.cpp b/src/plugins/projectexplorer/devicesupport/filetransfer.cpp index 8e36aacda55..54a135faf9e 100644 --- a/src/plugins/projectexplorer/devicesupport/filetransfer.cpp +++ b/src/plugins/projectexplorer/devicesupport/filetransfer.cpp @@ -45,18 +45,13 @@ static const FilePath &remoteFile(FileTransferDirection direction, const FileToT return direction == FileTransferDirection::Upload ? file.m_target : file.m_source; } -static bool isSameDevice(const FilePath &first, const FilePath &second) -{ - return (first.scheme() == second.scheme()) && (first.host() == second.host()); -} - static IDeviceConstPtr matchedDevice(FileTransferDirection direction, const FilesToTransfer &files) { if (files.isEmpty()) return {}; const FilePath &filePath = remoteFile(direction, files.first()); for (const FileToTransfer &file : files) { - if (!isSameDevice(filePath, remoteFile(direction, file))) + if (!filePath.isSameDevice(remoteFile(direction, file))) return {}; } return DeviceManager::deviceForPath(filePath);