From feb67bbdd202ac708cbf41f5698c4e2246ad4232 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 12 Oct 2023 15:58:34 -0700 Subject: [PATCH] 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 Reviewed-by: Ahmad Samir --- src/corelib/io/qstorageinfo_linux.cpp | 2 +- src/corelib/io/qstorageinfo_unix.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index 2910a4bfa3..e1f7fe65ac 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -259,7 +259,7 @@ QList QStorageInfoPrivate::mountedVolumes() for (MountInfo &info : infos) { QStorageInfoPrivate d(std::move(info)); d.retrieveVolumeInfo(); - if (d.bytesTotal == 0 && d.rootPath != u'/') + if (d.bytesTotal <= 0 && d.rootPath != u'/') continue; if (info.stDev != deviceIdForPath(d.rootPath)) continue; // probably something mounted over this mountpoint diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index af65823b1d..75d83a58d6 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -476,7 +476,7 @@ QList QStorageInfoPrivate::mountedVolumes() info.d->device = it.device(); info.d->fileSystemType = it.fileSystemType(); info.d->subvolume = it.subvolume(); - if (info.bytesTotal() == 0 && info != root()) + if (info.bytesTotal() <= 0 && info != root()) continue; volumes.append(info); }