QIOSFileEngineAssetsLibrary: bail out early on non-existing dirs

QFileSelector::selectionHelper walks through the list of selectors
(on iOS, on my phone it's ("ios", "iOS", "en_NO", "unix", "darwin")),
creating paths and testing QDir::exists. This ends up in asset
file engine trying to load asset for something like:
"assets-library://assets/+iOS" etc. ALAssetsLibrary -assetForUrl:
returns nil for such url and we start iterating through the assets
library. On my phone (e.g.) this takes about ~6 seconds (to iterate
through pictures/videos I have), so the image picker is dismissed
~30 seconds after an image was actually selected in a picker view,
making an impression it's completely broken. Bail out early
on such url, we know we'll fail (with AssetsLibrary giving a warning
about invalid asset with UUID(null).

Pick-to: 6.5
Fixes: QTBUG-109120
Change-Id: Ia302f4151e3aade830e647a8a260479df2b29d4b
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Timur Pocheptsov 2023-03-28 14:23:40 +02:00
parent 15d6244ec3
commit 9ddd71a6c2

View File

@ -11,6 +11,7 @@
#include <QtCore/qurl.h>
#include <QtCore/qset.h>
#include <QtCore/qthreadstorage.h>
#include <QtCore/qfileselector.h>
QT_BEGIN_NAMESPACE
@ -344,6 +345,17 @@ QAbstractFileEngine::FileFlags QIOSFileEngineAssetsLibrary::fileFlags(QAbstractF
{
QAbstractFileEngine::FileFlags flags;
const bool isDir = (m_assetUrl == "assets-library://"_L1);
if (!isDir) {
static const QFileSelector fileSelector;
static const auto selectors = fileSelector.allSelectors();
if (m_assetUrl.startsWith("assets-library://"_L1)) {
for (const auto &selector : selectors) {
if (m_assetUrl.endsWith(selector))
return flags;
}
}
}
const bool exists = isDir || m_assetUrl == g_iteratorCurrentUrl.localData() || loadAsset();
if (!exists)