forked from qt-creator/qt-creator
Utils: Make DeviceFileHooks access a bit more self-contained
Change-Id: Ib13035820021e9eda0585f98885bef9cbd2317a6 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -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
|
||||
|
@@ -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<bool(const FilePath &)> isExecutableFile;
|
||||
std::function<bool(const FilePath &)> isReadableFile;
|
||||
std::function<bool(const FilePath &)> isReadableDir;
|
||||
|
@@ -425,7 +425,7 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
||||
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
|
||||
this, &DeviceManager::save);
|
||||
|
||||
DeviceFileHooks deviceHooks;
|
||||
DeviceFileHooks &deviceHooks = DeviceFileHooks::instance();
|
||||
|
||||
deviceHooks.isExecutableFile = [](const FilePath &filePath) {
|
||||
auto device = DeviceManager::deviceForPath(filePath);
|
||||
@@ -610,8 +610,6 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
||||
return device->displayName();
|
||||
};
|
||||
|
||||
FilePath::setDeviceFileHooks(deviceHooks);
|
||||
|
||||
DeviceProcessHooks processHooks;
|
||||
|
||||
processHooks.processImplHook = [](const FilePath &filePath) -> ProcessInterface * {
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user