diff options
author | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-01-19 08:05:43 +0100 |
---|---|---|
committer | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-01-27 11:13:58 +0000 |
commit | 598ffc3b1c8cddf2381861e8d6f71b9b2050e66b (patch) | |
tree | 425f7a340c8deacf22e28439ce120ef8164b60d1 | |
parent | d36ecb23dfeae01935a8331ddcf517356493b3e0 (diff) | |
download | qt-creator-598ffc3b1c8cddf2381861e8d6f71b9b2050e66b.tar.gz |
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 <eike.ziller@qt.io>
-rw-r--r-- | src/libs/utils/devicefileaccess.cpp | 13 | ||||
-rw-r--r-- | src/libs/utils/fileutils.cpp | 14 | ||||
-rw-r--r-- | src/libs/utils/fsengine/fsengine_impl.cpp | 3 | ||||
-rw-r--r-- | 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 517004f273..9cc98a0d73 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 bfead072f9..196c115b17 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 e09bc94609..bea2547619 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 86611d6f91..2169078df0 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() |