From e55d7fa1e09efc86e797efdf00656891f640d81d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 4 Oct 2024 14:11:36 -0700 Subject: [PATCH] QStorageInfo/Unix: reset the valid state when doStat()ing again If the user calls setPath() or refresh(), we are going to stat the storage again. But neither retrieveVolumeInfo() nor initRootPath() unset the flag if the storage became invalid. This can't be tested automatically. Fixes: QTBUG-129689 Pick-to: 6.8 6.5 6.2 5.15 Change-Id: I8d4c5b4ed563e89f5723fffd2f550b169bb20884 Reviewed-by: Ahmad Samir --- src/corelib/io/qstorageinfo_linux.cpp | 6 ++---- src/corelib/io/qstorageinfo_unix.cpp | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index 26a62ffb8cf..00331a57127 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -408,10 +408,8 @@ void QStorageInfoPrivate::retrieveVolumeInfo() struct statfs64 statfs_buf; int result; QT_EINTR_LOOP(result, statfs64(QFile::encodeName(rootPath).constData(), &statfs_buf)); - if (result == 0) { - valid = true; - ready = true; - + valid = ready = (result == 0); + if (valid) { bytesTotal = statfs_buf.f_blocks * statfs_buf.f_frsize; bytesFree = statfs_buf.f_bfree * statfs_buf.f_frsize; bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize; diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index 9df098a3891..b809a52f974 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -390,6 +390,7 @@ static inline QString retrieveLabel(const QByteArray &device) void QStorageInfoPrivate::doStat() { + valid = ready = false; initRootPath(); if (rootPath.isEmpty()) return; @@ -403,10 +404,8 @@ void QStorageInfoPrivate::retrieveVolumeInfo() QT_STATFSBUF statfs_buf; int result; QT_EINTR_LOOP(result, QT_STATFS(QFile::encodeName(rootPath).constData(), &statfs_buf)); - if (result == 0) { - valid = true; - ready = true; - + valid = ready = (result == 0); + if (valid) { #if defined(Q_OS_INTEGRITY) || (defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD)) || defined(Q_OS_RTEMS) bytesTotal = statfs_buf.f_blocks * statfs_buf.f_bsize; bytesFree = statfs_buf.f_bfree * statfs_buf.f_bsize;