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.10 6.9 6.8 Change-Id: I8d93f6db83a28d70a192fffd6668734a8024b88b Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
parent
c5e6034bbd
commit
e1d418bcd0
@ -1080,9 +1080,18 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
|
||||
#endif
|
||||
|
||||
if (what & QFileSystemMetaData::HiddenAttribute
|
||||
&& !data.isHidden()) {
|
||||
QString fileName = entry.fileName();
|
||||
if (fileName.startsWith(u'.')
|
||||
&& !data.isHidden()) {
|
||||
// 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