From 20bf08f01215f16894d2937a23edf725d7575d84 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.5 6.2 5.15 Change-Id: I8d4c5b4ed563e89f5723fffd2f550b169bb20884 Reviewed-by: Ahmad Samir (cherry picked from commit e55d7fa1e09efc86e797efdf00656891f640d81d) Reviewed-by: Qt Cherry-pick Bot --- 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 b7ca498e9c4..f5be2454a24 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -197,10 +197,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;