Return QByteArray instead of bool in readData.

This commit is contained in:
Andrius Štikonas 2020-11-29 23:34:29 +00:00
parent 73da1bc514
commit a06d4ba0f7
3 changed files with 8 additions and 6 deletions

View File

@ -454,7 +454,8 @@ bool SfdiskBackend::updateDevicePartitionTable(Device &d, const QJsonObject &jso
CopySourceDevice source(d, 512, 1023); CopySourceDevice source(d, 512, 1023);
ExternalCommand readCmd; ExternalCommand readCmd;
if (readCmd.readData(source, gptHeader)) { gptHeader = readCmd.readData(source);
if (gptHeader != QByteArray()) {
QByteArray gptMaxEntries = gptHeader.mid(80, 4); QByteArray gptMaxEntries = gptHeader.mid(80, 4);
QDataStream stream(&gptMaxEntries, QIODevice::ReadOnly); QDataStream stream(&gptMaxEntries, QIODevice::ReadOnly);
stream.setByteOrder(QDataStream::LittleEndian); stream.setByteOrder(QDataStream::LittleEndian);

View File

@ -187,17 +187,18 @@ bool ExternalCommand::copyBlocks(const CopySource& source, CopyTarget& target)
return rval; return rval;
} }
bool ExternalCommand::readData(const CopySourceDevice& source, QByteArray& target) QByteArray ExternalCommand::readData(const CopySourceDevice& source)
{ {
auto interface = helperInterface(); auto interface = helperInterface();
if (!interface) if (!interface)
return false; return {};
QDBusPendingCall pcall = interface->ReadData(source.path(), source.firstByte(), source.length()); QDBusPendingCall pcall = interface->ReadData(source.path(), source.firstByte(), source.length());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
QEventLoop loop;
QEventLoop loop;
QByteArray target;
auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) { auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) {
loop.exit(); loop.exit();
@ -213,7 +214,7 @@ bool ExternalCommand::readData(const CopySourceDevice& source, QByteArray& targe
connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop); connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop);
loop.exec(); loop.exec();
return target != QByteArray(); return target;
} }
bool ExternalCommand::writeData(Report& commandReport, const QByteArray& buffer, const QString& deviceNode, const quint64 firstByte) bool ExternalCommand::writeData(Report& commandReport, const QByteArray& buffer, const QString& deviceNode, const quint64 firstByte)

View File

@ -55,7 +55,7 @@ public:
public: public:
bool copyBlocks(const CopySource& source, CopyTarget& target); bool copyBlocks(const CopySource& source, CopyTarget& target);
bool readData(const CopySourceDevice& source, QByteArray& target); QByteArray readData(const CopySourceDevice& source);
bool writeData(Report& commandReport, const QByteArray& buffer, const QString& deviceNode, const quint64 firstByte); // same as copyBlocks but from QByteArray bool writeData(Report& commandReport, const QByteArray& buffer, const QString& deviceNode, const quint64 firstByte); // same as copyBlocks but from QByteArray
bool createFile(const QByteArray& filePath, const QString& fileContents); // similar to writeData but creates a new file bool createFile(const QByteArray& filePath, const QString& fileContents); // similar to writeData but creates a new file