Fix few QFileInfo and QDir calls

Return the file engine impl of QFileInfo::completeBaseName() and
QDir::absolutePath() and QFileInfo::fileName() (based on
QAbstractFileEngine::BaseName) if the file engine impl is valid.

Amends f77668ffec.

Pick-to: 6.5 6.4 6.2 5.15
Task-number: QTBUG-98974
Change-Id: I28a8c75a6f25e30012b0791c12dbde51bfe8f62c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Assam Boudjelthia 2023-01-16 21:03:19 +02:00
parent 3a0c33da3d
commit 249d613a60
3 changed files with 13 additions and 7 deletions

View File

@ -662,7 +662,10 @@ QString QDir::path() const
QString QDir::absolutePath() const
{
Q_D(const QDir);
return d->resolveAbsoluteEntry();
if (!d->fileEngine)
return d->resolveAbsoluteEntry();
return d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
}
/*!

View File

@ -773,7 +773,9 @@ QString QFileInfo::fileName() const
Q_D(const QFileInfo);
if (d->isDefaultConstructed)
return ""_L1;
return d->fileEntry.fileName();
if (!d->fileEngine)
return d->fileEntry.fileName();
return d->fileEngine->fileName(QAbstractFileEngine::BaseName);
}
/*!
@ -817,7 +819,7 @@ QString QFileInfo::baseName() const
Q_D(const QFileInfo);
if (d->isDefaultConstructed)
return ""_L1;
if (!d_ptr->fileEngine)
if (!d->fileEngine)
return d->fileEntry.baseName();
return QFileSystemEntry(d->fileEngine->fileName(QAbstractFileEngine::BaseName)).baseName();
}
@ -838,7 +840,10 @@ QString QFileInfo::completeBaseName() const
Q_D(const QFileInfo);
if (d->isDefaultConstructed)
return ""_L1;
return d->fileEntry.completeBaseName();
if (!d->fileEngine)
return d->fileEntry.completeBaseName();
const QString fileEngineBaseName = d->fileEngine->fileName(QAbstractFileEngine::BaseName);
return QFileSystemEntry(fileEngineBaseName).completeBaseName();
}
/*!

View File

@ -53,7 +53,6 @@ void tst_ContentUris::dirFacilities()
const QDir subDir = dirList.first();
QVERIFY(subDir.dirName() == "Sub"_L1);
QEXPECT_FAIL("", "absolutePath() is returning wrong path, cutting from 'primary' onward", Continue);
qWarning() << "subDir.absolutePath()" << subDir.absolutePath() << dirList.first();
QVERIFY(subDir.absolutePath() == dirList.first());
QVERIFY(subDir.path() == dirList.first());
@ -67,7 +66,6 @@ void tst_ContentUris::dirFacilities()
QVERIFY(listFiles(dir, QDirIterator::Subdirectories).size() == 3);
QVERIFY(dir.mkpath("Sub/Sub2/Sub3")); // Create an existing dir hierarchy
QVERIFY(dir.rmdir("Sub"));
}
void tst_ContentUris::readWriteFile()
@ -83,7 +81,7 @@ void tst_ContentUris::readWriteFile()
QVERIFY(file.exists());
QVERIFY(file.size() == 0);
QVERIFY(file.fileName() == url);
QVERIFY(QFileInfo(url).baseName() == fileName);
QVERIFY(QFileInfo(url).completeBaseName() == fileName);
QVERIFY(file.open(QFile::WriteOnly));
QVERIFY(file.isOpen());