From 598ffc3b1c8cddf2381861e8d6f71b9b2050e66b Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 19 Jan 2023 08:05:43 +0100 Subject: [PATCH] Utils: Fake root info When trying to open a FileDialog all roots were tested for existence. This is slow and might show ask-pass. Since "/" can be considered always valid, we create a fake entry for it and only test existence of remote paths if they are not a root path. In the future FilePath should get a "isRoot()" function so we don't just test for == "/". Remove the fileAccess from WebAssembly devices. Change-Id: I7a1a6e7d2025e9fd4428e4bd1d07cdbdb5680c8e Reviewed-by: Eike Ziller --- src/libs/utils/devicefileaccess.cpp | 13 +++++++++++++ src/libs/utils/fileutils.cpp | 14 +++++++++----- src/libs/utils/fsengine/fsengine_impl.cpp | 3 +++ src/plugins/webassembly/webassemblydevice.cpp | 1 + 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/libs/utils/devicefileaccess.cpp b/src/libs/utils/devicefileaccess.cpp index 517004f2732..9cc98a0d739 100644 --- a/src/libs/utils/devicefileaccess.cpp +++ b/src/libs/utils/devicefileaccess.cpp @@ -829,6 +829,19 @@ QByteArray UnixDeviceFileAccess::fileId(const FilePath &filePath) const FilePathInfo UnixDeviceFileAccess::filePathInfo(const FilePath &filePath) const { + if (filePath.path() == "/") // TODO: Add FilePath::isRoot() + { + const FilePathInfo r{4096, + FilePathInfo::FileFlags( + FilePathInfo::ReadOwnerPerm | FilePathInfo::WriteOwnerPerm + | FilePathInfo::ExeOwnerPerm | FilePathInfo::ReadGroupPerm + | FilePathInfo::ExeGroupPerm | FilePathInfo::ReadOtherPerm + | FilePathInfo::ExeOtherPerm | FilePathInfo::DirectoryType + | FilePathInfo::LocalDiskFlag | FilePathInfo::ExistsFlag), + QDateTime::currentDateTime()}; + + return r; + } const RunResult stat = runInShell({"stat", {"-L", "-c", "%f %Y %s", filePath.path()}, OsType::OsTypeLinux}); return FileUtils::filePathInfoFromTriple(QString::fromLatin1(stat.stdOut)); } diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index bfead072f98..196c115b176 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -415,26 +415,30 @@ FilePath qUrlToFilePath(const QUrl &url) QUrl filePathToQUrl(const FilePath &filePath) { - return QUrl::fromLocalFile(filePath.toFSPathString()); + return QUrl::fromLocalFile(filePath.toFSPathString()); } void prepareNonNativeDialog(QFileDialog &dialog) { + const auto isValidSideBarPath = [](const FilePath &fp) { + return !fp.needsDevice() || fp.hasFileAccess(); + }; + // Checking QFileDialog::itemDelegate() seems to be the only way to determine // whether the dialog is native or not. if (dialog.itemDelegate()) { FilePaths sideBarPaths; - // Check existing urls, remove paths that need a device and no longer exist. + // Check existing urls, remove paths that need a device and are no longer valid. for (const QUrl &url : dialog.sidebarUrls()) { FilePath path = qUrlToFilePath(url); - if (!path.needsDevice() || path.exists()) + if (isValidSideBarPath(path)) sideBarPaths.append(path); } - // Add all device roots that are not already in the sidebar and exist. + // Add all device roots that are not already in the sidebar and valid. for (const FilePath &path : FSEngine::registeredDeviceRoots()) { - if (!sideBarPaths.contains(path) && path.exists()) + if (!sideBarPaths.contains(path) && isValidSideBarPath(path)) sideBarPaths.append(path); } diff --git a/src/libs/utils/fsengine/fsengine_impl.cpp b/src/libs/utils/fsengine/fsengine_impl.cpp index e09bc94609e..bea25476198 100644 --- a/src/libs/utils/fsengine/fsengine_impl.cpp +++ b/src/libs/utils/fsengine/fsengine_impl.cpp @@ -44,6 +44,9 @@ bool FSEngineImpl::open(QIODevice::OpenMode openMode) createCacheData); bool exists = (data.filePathInfo.fileFlags & QAbstractFileEngine::ExistsFlag); + if (data.filePathInfo.fileFlags & QAbstractFileEngine::DirectoryType) + return false; + g_filePathInfoCache.invalidate(m_filePath); ensureStorage(); diff --git a/src/plugins/webassembly/webassemblydevice.cpp b/src/plugins/webassembly/webassemblydevice.cpp index 86611d6f91e..2169078df0b 100644 --- a/src/plugins/webassembly/webassemblydevice.cpp +++ b/src/plugins/webassembly/webassemblydevice.cpp @@ -23,6 +23,7 @@ WebAssemblyDevice::WebAssemblyDevice() setDeviceState(IDevice::DeviceStateUnknown); setMachineType(IDevice::Hardware); setOsType(OsTypeOther); + setFileAccess(nullptr); } IDevice::Ptr WebAssemblyDevice::create()