Improve QFileInfo usage.
Cache QFileInfo result in a local variable. Before repeated request often incorrectly resulted in QString()
This commit is contained in:
parent
4a64465738
commit
d99b3f6eb3
|
@ -104,14 +104,12 @@ FstabEntryList readFstabEntries( const QString& fstabPath )
|
||||||
QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath)
|
QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath)
|
||||||
{
|
{
|
||||||
QStringList mountPoints;
|
QStringList mountPoints;
|
||||||
QFileInfo kernelPath(deviceNode);
|
QString canonicalPath = QFileInfo(deviceNode).canonicalFilePath();
|
||||||
QString canonicalPath = kernelPath.canonicalFilePath();
|
|
||||||
const FstabEntryList fstabEntryList = readFstabEntries( fstabPath );
|
const FstabEntryList fstabEntryList = readFstabEntries( fstabPath );
|
||||||
for (const FstabEntry &entry : fstabEntryList) {
|
for (const FstabEntry &entry : fstabEntryList)
|
||||||
QFileInfo kernelPath2(entry.deviceNode());
|
if (QFileInfo(entry.deviceNode()).canonicalFilePath() == canonicalPath)
|
||||||
if (kernelPath2.canonicalFilePath() == canonicalPath)
|
|
||||||
mountPoints.append(entry.mountPoint());
|
mountPoints.append(entry.mountPoint());
|
||||||
}
|
|
||||||
return mountPoints;
|
return mountPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,9 +332,10 @@ bool Partition::unmount(Report& report)
|
||||||
success = fileSystem().unmount(report, deviceNode());
|
success = fileSystem().unmount(report, deviceNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString canonicalDeviceNode = QFileInfo(deviceNode()).canonicalFilePath();
|
||||||
const QList<QStorageInfo> mountedVolumes = QStorageInfo::mountedVolumes();
|
const QList<QStorageInfo> mountedVolumes = QStorageInfo::mountedVolumes();
|
||||||
for (const QStorageInfo &storage : mountedVolumes) {
|
for (const QStorageInfo &storage : mountedVolumes) {
|
||||||
if (QString::fromUtf8(storage.device()) == deviceNode() ) {
|
if (QFileInfo(QString::fromUtf8(storage.device())).canonicalFilePath() == canonicalDeviceNode ) {
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,10 +135,10 @@ QString FileSystem::detectMountPoint(FileSystem* fs, const QString& partitionPat
|
||||||
|
|
||||||
QStringList mountPoints;
|
QStringList mountPoints;
|
||||||
QFileInfo partitionPathFileInfo(partitionPath);
|
QFileInfo partitionPathFileInfo(partitionPath);
|
||||||
|
QString partitionCanonicalPath = partitionPathFileInfo.canonicalFilePath();
|
||||||
const QList<QStorageInfo> mountedVolumes = QStorageInfo::mountedVolumes();
|
const QList<QStorageInfo> mountedVolumes = QStorageInfo::mountedVolumes();
|
||||||
for (const QStorageInfo &storage : mountedVolumes) {
|
for (const QStorageInfo &storage : mountedVolumes) {
|
||||||
QFileInfo deviceFileInfo(QString::fromUtf8(storage.device()));
|
if (partitionCanonicalPath == QFileInfo(QString::fromUtf8(storage.device())).canonicalFilePath() ) {
|
||||||
if (partitionPathFileInfo.canonicalFilePath() == deviceFileInfo.canonicalFilePath() ) {
|
|
||||||
mountPoints.append(storage.rootPath());
|
mountPoints.append(storage.rootPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue