QStorageInfo/Linux: simplify the code to deal with skipped entries

In addition to what parseMountInfo() filtered, we also filter entries
with zero total bytes (other than the root filesystem). This avoids
creating yet another QStorageInfoPrivate that may not be used, but most
importantly it avoids calling root() for that check, which would call
parseMountInfo() again.

Pick-to: 6.6
Change-Id: I9d43e5b91eb142d6945cfffd1787538dd3f285d0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Thiago Macieira 2023-09-22 13:47:33 -07:00
parent c82ed8b279
commit df8514a764

View File

@ -166,11 +166,10 @@ QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
for (MountInfo &info : infos) {
QStorageInfoPrivate d(std::move(info));
d.retrieveVolumeInfo();
QStorageInfo storage(*new QStorageInfoPrivate(std::move(d)));
if (storage.bytesTotal() == 0 && storage != root())
if (d.bytesTotal == 0 && d.rootPath != u'/')
continue;
storage.d->name = retrieveLabel(storage.d->device);
volumes.push_back(storage);
d.name = retrieveLabel(d.device);
volumes.emplace_back(QStorageInfo(*new QStorageInfoPrivate(std::move(d))));
}
return volumes;
}