From 9ddd71a6c2b6cef641f2a8cdc256fb2fbe01fa5b Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 28 Mar 2023 14:23:40 +0200 Subject: [PATCH] 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 --- .../qiosfileengineassetslibrary.mm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm index 0ca911f68b..312899f3d9 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm @@ -11,6 +11,7 @@ #include #include #include +#include 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)