fix device RO check

Summary:
- mark deviceNode const
- copy it as deviceName
- mutate deviceName by removing `/dev/`
- use the new deviceName for the read-only check

this makes sure we emit the unmodified deviceNode (e.g. /dev/vda) rather
than the name (e.g. vda). unbreaks for example calamares which doesn't
know what to do with "vda".

CCBUG: 378607

Test Plan:
- without fix clamares fails to list devices
- with the fix calamares lists devices

Reviewers: stikonas

Reviewed By: stikonas

Differential Revision: https://phabricator.kde.org/D6414
This commit is contained in:
Harald Sitter 2017-06-28 10:11:33 +02:00
parent a35702e911
commit 984a4e9ace
1 changed files with 4 additions and 2 deletions

View File

@ -429,9 +429,11 @@ QList<Device*> LibPartedBackend::scanDevices(bool excludeReadOnly)
const QStringList output=cmd.output().split(QStringLiteral("\n")).filter(QRegularExpression(QStringLiteral("^disk ")));
quint32 totalDevices = output.length();
for (quint32 i = 0; i < totalDevices; ++i) {
QString deviceNode = output[i].split(QStringLiteral(" ")).last();
const QString deviceNode = output[i].split(QStringLiteral(" ")).last();
if (excludeReadOnly) {
QFile f(QStringLiteral("/sys/block/%1/ro").arg(deviceNode.remove(QStringLiteral("/dev/"))));
auto deviceName = deviceNode;
deviceName.remove(QStringLiteral("/dev/"));
QFile f(QStringLiteral("/sys/block/%1/ro").arg(deviceName));
if (f.open(QIODevice::ReadOnly))
if (f.readLine().trimmed().toInt() == 1)
continue;