QFileSystemEngine/Unix: avoid an unnecessary conversion to QString
Sometimes, fillMetaData() is called with a QFileSystemEntry with only the native (QByteArray) format, which we used above in this function anyway in order to lstat() and stat() the path. This avoids forcing the QFSE to create the QString form for us to check the first character. Pick-to: 6.9 6.8 Change-Id: I8d93f6db83a28d70a192fffd6668734a8024b88b Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit e1d418bcd07aba891da79c653f5b0e3c6852fb30) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
5f758f7af6
commit
8e7ddf261e
@ -1081,8 +1081,17 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
|
||||
|
||||
if (what & QFileSystemMetaData::HiddenAttribute
|
||||
&& !data.isHidden()) {
|
||||
QString fileName = entry.fileName();
|
||||
if (fileName.startsWith(u'.')
|
||||
// reusing nativeFilePath from above instead of entry.fileName(), to
|
||||
// avoid memory allocation for the QString result.
|
||||
qsizetype lastSlash = nativeFilePath.size();
|
||||
|
||||
while (lastSlash && nativeFilePath.at(lastSlash - 1) == '/')
|
||||
--lastSlash; // skip ending slashes
|
||||
while (lastSlash && nativeFilePath.at(lastSlash - 1) != '/')
|
||||
--lastSlash; // skip non-slashes
|
||||
--lastSlash; // point to the slash or -1 if no slash
|
||||
|
||||
if (nativeFilePath.at(lastSlash + 1) == '.'
|
||||
#if defined(Q_OS_DARWIN)
|
||||
|| (entryErrno == 0 && hasResourcePropertyFlag(data, entry, kCFURLIsHiddenKey))
|
||||
#endif
|
||||
|
@ -1656,14 +1656,26 @@ void tst_QFileInfo::isHidden_data()
|
||||
#if defined(Q_OS_WIN)
|
||||
QVERIFY(QDir("./hidden-directory").exists() || QDir().mkdir("./hidden-directory"));
|
||||
QVERIFY(SetFileAttributesW(reinterpret_cast<LPCWSTR>(QString("./hidden-directory").utf16()),FILE_ATTRIBUTE_HIDDEN));
|
||||
QTest::newRow("hidden-directory") << QString::fromLatin1("hidden-directory") << true;
|
||||
QTest::newRow("C:/path/to/hidden-directory") << QDir::currentPath() + QString::fromLatin1("/hidden-directory") << true;
|
||||
QTest::newRow("C:/path/to/hidden-directory/.") << QDir::currentPath() + QString::fromLatin1("/hidden-directory/.") << true;
|
||||
#endif
|
||||
#if defined(Q_OS_UNIX)
|
||||
QVERIFY(QDir("./.hidden-directory").exists() || QDir().mkdir("./.hidden-directory"));
|
||||
QTest::newRow(".hidden-directory") << QString(".hidden-directory") << true;
|
||||
QTest::newRow(".hidden-directory/") << QString(".hidden-directory/") << true;
|
||||
QTest::newRow(".hidden-directory//") << QString(".hidden-directory//") << true;
|
||||
QTest::newRow(".hidden-directory/.") << QString(".hidden-directory/.") << true;
|
||||
QTest::newRow(".hidden-directory//.") << QString(".hidden-directory//.") << true;
|
||||
QTest::newRow(".hidden-directory/..") << QString(".hidden-directory/..") << true;
|
||||
QTest::newRow(".hidden-directory//..") << QString(".hidden-directory//..") << true;
|
||||
QTest::newRow("/path/to/.hidden-directory") << QDir::currentPath() + QString("/.hidden-directory") << true;
|
||||
QTest::newRow("/path/to/.hidden-directory/") << QDir::currentPath() + QString("/.hidden-directory/") << true;
|
||||
QTest::newRow("/path/to/.hidden-directory//") << QDir::currentPath() + QString("/.hidden-directory//") << true;
|
||||
QTest::newRow("/path/to/.hidden-directory/.") << QDir::currentPath() + QString("/.hidden-directory/.") << true;
|
||||
QTest::newRow("/path/to/.hidden-directory//.") << QDir::currentPath() + QString("/.hidden-directory//.") << true;
|
||||
QTest::newRow("/path/to/.hidden-directory/..") << QDir::currentPath() + QString("/.hidden-directory/..") << true;
|
||||
QTest::newRow("/path/to/.hidden-directory//..") << QDir::currentPath() + QString("/.hidden-directory//..") << true;
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_DARWIN)
|
||||
|
Loading…
x
Reference in New Issue
Block a user