forked from qt-creator/qt-creator
linuxdevice: Fix ::bytesAvailable
DeviceShell does not support piping commands at the moment. To continue to support ::bytesAvailable the parsing of the output from "df" is moved to FileUtils::bytesAvailableFromDFOutput. Change-Id: Ia229208748aa6c572b99899e6ae042bdd5654f4a Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -531,4 +531,26 @@ void FileUtils::iterateLsOutput(const FilePath &base,
|
||||
|
||||
#endif // QT_WIDGETS_LIB
|
||||
|
||||
qint64 FileUtils::bytesAvailableFromDFOutput(const QByteArray &dfOutput)
|
||||
{
|
||||
const auto lines = filtered(dfOutput.split('\n'),
|
||||
[](const QByteArray &line) { return line.size() > 0; });
|
||||
|
||||
QTC_ASSERT(lines.size() == 2, return -1);
|
||||
const auto headers = filtered(lines[0].split(' '),
|
||||
[](const QByteArray &field) { return field.size() > 0; });
|
||||
QTC_ASSERT(headers.size() >= 4, return -1);
|
||||
QTC_ASSERT(headers[3] == QByteArray("Available"), return -1);
|
||||
|
||||
const auto fields = filtered(lines[1].split(' '),
|
||||
[](const QByteArray &field) { return field.size() > 0; });
|
||||
QTC_ASSERT(fields.size() >= 4, return -1);
|
||||
|
||||
bool ok = false;
|
||||
const quint64 result = QString::fromUtf8(fields[3]).toULongLong(&ok);
|
||||
if (ok)
|
||||
return result;
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user