From 8945b3832c3a9bc2d6ea09e7d9a38737fd08974e Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 4 Aug 2022 10:44:45 +0200 Subject: [PATCH] Utils: Make DeviceFileHooks access a bit more self-contained Change-Id: Ib13035820021e9eda0585f98885bef9cbd2317a6 Reviewed-by: Marcus Tillmanns Reviewed-by: hjk --- src/libs/utils/filepath.cpp | 10 +++++----- src/libs/utils/filepath.h | 7 +++---- .../projectexplorer/devicesupport/devicemanager.cpp | 4 +--- tests/auto/utils/fsengine/tst_fsengine.cpp | 4 +--- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index fd15deb05d3..d05100e2057 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -65,6 +65,11 @@ namespace Utils { static DeviceFileHooks s_deviceHooks; +DeviceFileHooks &DeviceFileHooks::instance() +{ + return s_deviceHooks; +} + static bool removeRecursivelyLocal(const FilePath &filePath, QString *error) { @@ -118,11 +123,6 @@ static bool removeRecursivelyLocal(const FilePath &filePath, QString *error) return true; } -void FilePath::setDeviceFileHooks(const DeviceFileHooks &hooks) -{ - s_deviceHooks = hooks; -} - /*! If this is a directory, the function will recursively check all files and return true if one of them is newer than \a timeStamp. If this is a single file, true will diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 09a4113c39f..7beeeb3c913 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -47,7 +47,6 @@ class tst_fileutils; // This becomes a friend of Utils::FilePath for testing pri namespace Utils { -class DeviceFileHooks; class Environment; class EnvironmentChange; @@ -225,8 +224,6 @@ public: [[nodiscard]] static QString specialPath(SpecialPathComponent component); [[nodiscard]] static FilePath specialFilePath(SpecialPathComponent component); - static void setDeviceFileHooks(const DeviceFileHooks &hooks); - private: friend class ::tst_fileutils; static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath); @@ -243,9 +240,11 @@ inline size_t qHash(const Utils::FilePath &a, uint seed = 0) return a.hash(seed); } -class DeviceFileHooks +class QTCREATOR_UTILS_EXPORT DeviceFileHooks { public: + static DeviceFileHooks &instance(); + std::function isExecutableFile; std::function isReadableFile; std::function isReadableDir; diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index 4683230af69..16aeae39108 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -425,7 +425,7 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_uniquedisplayName(); }; - FilePath::setDeviceFileHooks(deviceHooks); - DeviceProcessHooks processHooks; processHooks.processImplHook = [](const FilePath &filePath) -> ProcessInterface * { diff --git a/tests/auto/utils/fsengine/tst_fsengine.cpp b/tests/auto/utils/fsengine/tst_fsengine.cpp index 75c636b6bac..5fb9b215f2d 100644 --- a/tests/auto/utils/fsengine/tst_fsengine.cpp +++ b/tests/auto/utils/fsengine/tst_fsengine.cpp @@ -74,7 +74,7 @@ void tst_fsengine::initTestCase() if (!FSEngine::isAvailable()) QSKIP("Utils was built without Filesystem Engine"); - DeviceFileHooks deviceHooks; + DeviceFileHooks &deviceHooks = DeviceFileHooks::instance(); deviceHooks.fileContents = [](const FilePath &path, qint64 maxSize, qint64 offset) -> QByteArray { @@ -175,8 +175,6 @@ void tst_fsengine::initTestCase() deviceHooks.mapToDevicePath = [](const FilePath &filePath) { return filePath.path(); }; - FilePath::setDeviceFileHooks(deviceHooks); - FSEngine::addDevice(FilePath::fromString("device://test")); tempFolder = QDir::tempPath();