mirror of https://github.com/qt/qtbase.git
Fix sizes QStorageInfo returns for invalid drives
Zero is a legitimate size to be returned by bytesFree/bytesAvailable functions, so change those functions to return some 'invalid' size in case of an invalid drive. This is also consistent with the original version from the Qt Systems framework. [ChangeLog][QtCore][QStorageInfo] Fixed sizes returned for invalid drives. Task-number: QTBUG-45724 Change-Id: I312fba521fdf8d52d7a0ac0e46cacca625775e80 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
827e195f17
commit
9a029c9de4
|
@ -186,6 +186,8 @@ QString QStorageInfo::rootPath() const
|
||||||
This size can be less than or equal to the free size returned by
|
This size can be less than or equal to the free size returned by
|
||||||
bytesFree() function.
|
bytesFree() function.
|
||||||
|
|
||||||
|
Returns -1 if QStorageInfo object is not valid.
|
||||||
|
|
||||||
\sa bytesTotal(), bytesFree()
|
\sa bytesTotal(), bytesFree()
|
||||||
*/
|
*/
|
||||||
qint64 QStorageInfo::bytesAvailable() const
|
qint64 QStorageInfo::bytesAvailable() const
|
||||||
|
@ -198,6 +200,8 @@ qint64 QStorageInfo::bytesAvailable() const
|
||||||
quotas on the filesystem, this value can be larger than the value
|
quotas on the filesystem, this value can be larger than the value
|
||||||
returned by bytesAvailable().
|
returned by bytesAvailable().
|
||||||
|
|
||||||
|
Returns -1 if QStorageInfo object is not valid.
|
||||||
|
|
||||||
\sa bytesTotal(), bytesAvailable()
|
\sa bytesTotal(), bytesAvailable()
|
||||||
*/
|
*/
|
||||||
qint64 QStorageInfo::bytesFree() const
|
qint64 QStorageInfo::bytesFree() const
|
||||||
|
@ -208,6 +212,8 @@ qint64 QStorageInfo::bytesFree() const
|
||||||
/*!
|
/*!
|
||||||
Returns the total volume size in bytes.
|
Returns the total volume size in bytes.
|
||||||
|
|
||||||
|
Returns -1 if QStorageInfo object is not valid.
|
||||||
|
|
||||||
\sa bytesFree(), bytesAvailable()
|
\sa bytesFree(), bytesAvailable()
|
||||||
*/
|
*/
|
||||||
qint64 QStorageInfo::bytesTotal() const
|
qint64 QStorageInfo::bytesTotal() const
|
||||||
|
|
|
@ -53,7 +53,7 @@ class QStorageInfoPrivate : public QSharedData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline QStorageInfoPrivate() : QSharedData(),
|
inline QStorageInfoPrivate() : QSharedData(),
|
||||||
bytesTotal(0), bytesFree(0), bytesAvailable(0),
|
bytesTotal(-1), bytesFree(-1), bytesAvailable(-1),
|
||||||
readOnly(false), ready(false), valid(false)
|
readOnly(false), ready(false), valid(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
@ -61,9 +61,9 @@ void tst_QStorageInfo::defaultValues()
|
||||||
QVERIFY(!storage.isRoot());
|
QVERIFY(!storage.isRoot());
|
||||||
QVERIFY(storage.device().isEmpty());
|
QVERIFY(storage.device().isEmpty());
|
||||||
QVERIFY(storage.fileSystemType().isEmpty());
|
QVERIFY(storage.fileSystemType().isEmpty());
|
||||||
QVERIFY(storage.bytesTotal() == 0);
|
QVERIFY(storage.bytesTotal() == -1);
|
||||||
QVERIFY(storage.bytesFree() == 0);
|
QVERIFY(storage.bytesFree() == -1);
|
||||||
QVERIFY(storage.bytesAvailable() == 0);
|
QVERIFY(storage.bytesAvailable() == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QStorageInfo::operatorEqual()
|
void tst_QStorageInfo::operatorEqual()
|
||||||
|
@ -106,9 +106,9 @@ void tst_QStorageInfo::root()
|
||||||
QVERIFY(!storage.device().isEmpty());
|
QVERIFY(!storage.device().isEmpty());
|
||||||
QVERIFY(!storage.fileSystemType().isEmpty());
|
QVERIFY(!storage.fileSystemType().isEmpty());
|
||||||
#ifndef Q_OS_HAIKU
|
#ifndef Q_OS_HAIKU
|
||||||
QVERIFY(storage.bytesTotal() > 0);
|
QVERIFY(storage.bytesTotal() >= 0);
|
||||||
QVERIFY(storage.bytesFree() > 0);
|
QVERIFY(storage.bytesFree() >= 0);
|
||||||
QVERIFY(storage.bytesAvailable() > 0);
|
QVERIFY(storage.bytesAvailable() >= 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,9 +121,9 @@ void tst_QStorageInfo::currentStorage()
|
||||||
QVERIFY(appPath.startsWith(storage.rootPath(), Qt::CaseInsensitive));
|
QVERIFY(appPath.startsWith(storage.rootPath(), Qt::CaseInsensitive));
|
||||||
QVERIFY(!storage.device().isEmpty());
|
QVERIFY(!storage.device().isEmpty());
|
||||||
QVERIFY(!storage.fileSystemType().isEmpty());
|
QVERIFY(!storage.fileSystemType().isEmpty());
|
||||||
QVERIFY(storage.bytesTotal() > 0);
|
QVERIFY(storage.bytesTotal() >= 0);
|
||||||
QVERIFY(storage.bytesFree() > 0);
|
QVERIFY(storage.bytesFree() >= 0);
|
||||||
QVERIFY(storage.bytesAvailable() > 0);
|
QVERIFY(storage.bytesAvailable() >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QStorageInfo::storageList()
|
void tst_QStorageInfo::storageList()
|
||||||
|
|
Loading…
Reference in New Issue