forked from qt-creator/qt-creator
Filepath: Add ensureReachable function
ensureReachable checks whether the device (if any) of the filepath can "reach" another FilePath. Devices can then either return false if they don't, or take action to ensure that the path can be reached. Change-Id: Ic1a315b9e7d9e37ee649989313a4cdb195a7e4d9 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -559,6 +559,18 @@ std::optional<QByteArray> FilePath::fileContents(qint64 maxSize, qint64 offset)
|
|||||||
return f.readAll();
|
return f.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FilePath::ensureReachable(const FilePath &other) const
|
||||||
|
{
|
||||||
|
if (needsDevice()) {
|
||||||
|
QTC_ASSERT(s_deviceHooks.ensureReachable, return false);
|
||||||
|
return s_deviceHooks.ensureReachable(*this, other);
|
||||||
|
} else if (!other.needsDevice()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void FilePath::asyncFileContents(const Continuation<const std::optional<QByteArray> &> &cont,
|
void FilePath::asyncFileContents(const Continuation<const std::optional<QByteArray> &> &cont,
|
||||||
qint64 maxSize,
|
qint64 maxSize,
|
||||||
qint64 offset) const
|
qint64 offset) const
|
||||||
|
@@ -201,6 +201,8 @@ public:
|
|||||||
[[nodiscard]] static QString specialPath(SpecialPathComponent component);
|
[[nodiscard]] static QString specialPath(SpecialPathComponent component);
|
||||||
[[nodiscard]] static FilePath specialFilePath(SpecialPathComponent component);
|
[[nodiscard]] static FilePath specialFilePath(SpecialPathComponent component);
|
||||||
|
|
||||||
|
[[nodiscard]] bool ensureReachable(const FilePath &other) const;
|
||||||
|
|
||||||
QString toFSPathString() const;
|
QString toFSPathString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -265,6 +267,7 @@ public:
|
|||||||
const Continuation<const std::optional<QByteArray> &> &, const FilePath &, qint64, qint64)>
|
const Continuation<const std::optional<QByteArray> &> &, const FilePath &, qint64, qint64)>
|
||||||
asyncFileContents;
|
asyncFileContents;
|
||||||
std::function<void(const Continuation<bool> &, const FilePath &, const QByteArray &)> asyncWriteFileContents;
|
std::function<void(const Continuation<bool> &, const FilePath &, const QByteArray &)> asyncWriteFileContents;
|
||||||
|
std::function<bool(const FilePath &, const FilePath &)> ensureReachable;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -591,6 +591,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
|||||||
return device->displayName();
|
return device->displayName();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
deviceHooks.ensureReachable = [](const FilePath &filePath, const FilePath &other) {
|
||||||
|
auto device = DeviceManager::deviceForPath(filePath);
|
||||||
|
QTC_ASSERT(device, return false);
|
||||||
|
return device->ensureReachable(other);
|
||||||
|
};
|
||||||
|
|
||||||
DeviceProcessHooks processHooks;
|
DeviceProcessHooks processHooks;
|
||||||
|
|
||||||
processHooks.processImplHook = [](const FilePath &filePath) -> ProcessInterface * {
|
processHooks.processImplHook = [](const FilePath &filePath) -> ProcessInterface * {
|
||||||
|
@@ -816,6 +816,12 @@ QString IDevice::defaultPublicKeyFilePath()
|
|||||||
return defaultPrivateKeyFilePath() + QLatin1String(".pub");
|
return defaultPrivateKeyFilePath() + QLatin1String(".pub");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IDevice::ensureReachable(const FilePath &other) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(other)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceProcessSignalOperation::setDebuggerCommand(const FilePath &cmd)
|
void DeviceProcessSignalOperation::setDebuggerCommand(const FilePath &cmd)
|
||||||
{
|
{
|
||||||
m_debuggerCommand = cmd;
|
m_debuggerCommand = cmd;
|
||||||
|
@@ -261,6 +261,8 @@ public:
|
|||||||
const Utils::FilePath &filePath,
|
const Utils::FilePath &filePath,
|
||||||
const QByteArray &data) const;
|
const QByteArray &data) const;
|
||||||
|
|
||||||
|
virtual bool ensureReachable(const Utils::FilePath &other) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IDevice();
|
IDevice();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user