Filepath: Add ::isSameDevice

Change-Id: I3990429b59759d5f72ed95e3a0d1723d3bb7bb82
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-09-16 10:26:41 +02:00
parent f736c23afc
commit df859d891d
5 changed files with 24 additions and 14 deletions

View File

@@ -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
{

View File

@@ -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<qint64(const FilePath &)> fileSize;
std::function<qint64(const FilePath &)> bytesAvailable;
std::function<QString(const FilePath &)> deviceDisplayName;
std::function<bool(const FilePath &, const FilePath &)> isSameDevice;
template <class ...Args> using Continuation = std::function<void(Args...)>;
std::function<void(const Continuation<bool> &, const FilePath &, const FilePath &)> asyncCopyFile;

View File

@@ -864,14 +864,7 @@ void CMakeBuildSystem::ensureBuildDirectory(const BuildDirParameters &parameters
}
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."));

View File

@@ -429,6 +429,13 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
return device->isWritableDirectory(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);

View File

@@ -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);