QStorageInfo: use the same code on Linux and Android

/proc/self/mountinfo is available on Android too AFAIK (it's available
on an old Android 6.0 phone I have).

Change-Id: Ia4b04a143b362c7a18773716a90897ce4c5fc5f0
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Ahmad Samir 2023-05-09 01:17:44 +03:00
parent 961ff0cc8a
commit fe4f977a2d

View File

@ -25,7 +25,6 @@
#elif defined(Q_OS_ANDROID)
# include <sys/mount.h>
# include <sys/vfs.h>
# include <mntent.h>
#elif defined(Q_OS_LINUX)
# include <sys/statvfs.h>
#elif defined(Q_OS_HURD)
@ -112,12 +111,6 @@ private:
#elif defined(Q_OS_SOLARIS)
FILE *fp;
mnttab mnt;
#elif defined(Q_OS_ANDROID)
QFile file;
QByteArray m_rootPath;
QByteArray m_fileSystemType;
QByteArray m_device;
QByteArray m_options;
#elif defined(Q_OS_HURD)
FILE *fp;
QByteArray buffer;
@ -220,66 +213,6 @@ inline QByteArray QStorageIterator::device() const
return QByteArray(mnt.mnt_mntopts);
}
inline QByteArray QStorageIterator::subvolume() const
{
return QByteArray();
}
#elif defined(Q_OS_ANDROID)
inline QStorageIterator::QStorageIterator()
{
file.setFileName(QString::fromUtf8(_PATH_MOUNTED));
file.open(QIODevice::ReadOnly | QIODevice::Text);
}
inline QStorageIterator::~QStorageIterator()
{
}
inline bool QStorageIterator::isValid() const
{
return file.isOpen();
}
inline bool QStorageIterator::next()
{
QList<QByteArray> data;
// If file is virtual, file.readLine() may succeed even when file.atEnd().
do {
const QByteArray line = file.readLine();
if (line.isEmpty() && file.atEnd())
return false;
data = line.split(' ');
} while (data.count() < 4);
m_device = data.at(0);
m_rootPath = data.at(1);
m_fileSystemType = data.at(2);
m_options = data.at(3);
return true;
}
inline QString QStorageIterator::rootPath() const
{
return QFile::decodeName(m_rootPath);
}
inline QByteArray QStorageIterator::fileSystemType() const
{
return m_fileSystemType;
}
inline QByteArray QStorageIterator::device() const
{
return m_device;
}
inline QByteArray QStorageIterator::options() const
{
return m_options;
}
inline QByteArray QStorageIterator::subvolume() const
{
return QByteArray();
@ -553,8 +486,7 @@ void QStorageInfoPrivate::retrieveVolumeInfo()
}
}
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
#if defined(Q_OS_LINUX)
static std::vector<MountInfo> parseMountInfo(FilterMountInfo filter = FilterMountInfo::All)
{
QFile file(u"/proc/self/mountinfo"_s);
@ -614,9 +546,7 @@ QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
}
return volumes;
}
#else // defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
#else // defined(Q_OS_LINUX)
void QStorageInfoPrivate::initRootPath()
{
rootPath = QFileInfo(rootPath).canonicalFilePath();
@ -672,7 +602,7 @@ QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
return volumes;
}
#endif // defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
#endif // defined(Q_OS_LINUX)
QStorageInfo QStorageInfoPrivate::root()
{