QStorageInfo/Unix: exclude invalid volumes from mountedVolumes()

Invalid are usually those mounted on a filesystem we can't access:

$ df /run/user/0/gvfs
df: /run/user/0/gvfs: Permission denied
$ ./qstorageinfo /run/user/0/gvfs
Could not get info on /run/user/0/gvfs

df already doesn't include it by default:

$ df | grep -c gvfs
0

But we were:

$./qstorageinfo | sed -n '1p;/gvfs/p'
Filesystem (Type)                        Size  Available BSize  Label   Mounted on
gvfsd-fuse (fuse.gvfsd-fuse)    RW          0          0     0          /run/user/0/gvfs

Note also how this is showing a total size of 0, which is usually the
type of filesystem we exclude. It's actually -1 but got rounded down to
0 when we divided by 1024.

Pick-to: 6.6
Change-Id: I8f3ce163ccc5408cac39fffd178d7e4f9dc13b24
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
Thiago Macieira 2023-10-12 15:58:34 -07:00
parent 39843b65f4
commit feb67bbdd2
2 changed files with 2 additions and 2 deletions

View File

@ -259,7 +259,7 @@ QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
for (MountInfo &info : infos) { for (MountInfo &info : infos) {
QStorageInfoPrivate d(std::move(info)); QStorageInfoPrivate d(std::move(info));
d.retrieveVolumeInfo(); d.retrieveVolumeInfo();
if (d.bytesTotal == 0 && d.rootPath != u'/') if (d.bytesTotal <= 0 && d.rootPath != u'/')
continue; continue;
if (info.stDev != deviceIdForPath(d.rootPath)) if (info.stDev != deviceIdForPath(d.rootPath))
continue; // probably something mounted over this mountpoint continue; // probably something mounted over this mountpoint

View File

@ -476,7 +476,7 @@ QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
info.d->device = it.device(); info.d->device = it.device();
info.d->fileSystemType = it.fileSystemType(); info.d->fileSystemType = it.fileSystemType();
info.d->subvolume = it.subvolume(); info.d->subvolume = it.subvolume();
if (info.bytesTotal() == 0 && info != root()) if (info.bytesTotal() <= 0 && info != root())
continue; continue;
volumes.append(info); volumes.append(info);
} }