Utils: Shortcut File reading

If the device can point us to the local equivalent of a file we can
read that one instead.

Change-Id: I002b5babae13677d5814b639ca40a62f23a8b374
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-04-02 12:58:17 +02:00
parent 2626af4cd4
commit 1c905c6980

View File

@@ -1059,6 +1059,10 @@ expected_str<QByteArray> UnixDeviceFileAccess::fileContents(const FilePath &file
if (disconnected())
return make_unexpected_disconnected();
expected_str<FilePath> localSource = filePath.localSource();
if (localSource && *localSource != filePath)
return localSource->fileContents(limit, offset);
QStringList args = {"if=" + filePath.path()};
if (limit > 0 || offset > 0) {
const qint64 gcd = std::gcd(limit, offset);
@@ -1088,6 +1092,10 @@ expected_str<qint64> UnixDeviceFileAccess::writeFileContents(const FilePath &fil
if (disconnected())
return make_unexpected_disconnected();
expected_str<FilePath> localSource = filePath.localSource();
if (localSource && *localSource != filePath)
return localSource->writeFileContents(data);
QStringList args = {"of=" + filePath.path()};
RunResult result = runInShell({"dd", args, OsType::OsTypeLinux}, data);