From 267bdad28a219af6c76f564224369007e295f31a Mon Sep 17 00:00:00 2001 From: deepin-ci-robot Date: Fri, 18 Oct 2024 08:50:41 +0000 Subject: [PATCH] sync: from linuxdeepin/dtkcore Synchronize source files from linuxdeepin/dtkcore. Source-pull-request: https://github.com/linuxdeepin/dtkcore/pull/438 --- src/dci/private/ddcifileengine.cpp | 79 ++++++++++++++--------------- src/dci/private/ddcifileengine_p.h | 15 +++--- src/filesystem/dcapfsfileengine.cpp | 32 +++++++----- 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/src/dci/private/ddcifileengine.cpp b/src/dci/private/ddcifileengine.cpp index 49ffb18..574ff88 100644 --- a/src/dci/private/ddcifileengine.cpp +++ b/src/dci/private/ddcifileengine.cpp @@ -30,7 +30,7 @@ Q_LOGGING_CATEGORY(logFE, "dtk.dci.fileengine", QtInfoMsg) #define DCI_FILE_SCHEME "dci:" #define DCI_FILE_SUFFIX ".dci" -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) std::unique_ptr DDciFileEngineHandler::create(const QString &fileName) const #else QAbstractFileEngine *DDciFileEngineHandler::create(const QString &fileName) const @@ -39,7 +39,7 @@ QAbstractFileEngine *DDciFileEngineHandler::create(const QString &fileName) cons if (!fileName.startsWith(QStringLiteral(DCI_FILE_SCHEME))) return nullptr; -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) std::unique_ptr engine(new DDciFileEngine(fileName)); #else DDciFileEngine *engine = new DDciFileEngine(fileName); @@ -56,7 +56,8 @@ QAbstractFileEngine *DDciFileEngineHandler::create(const QString &fileName) cons // 共享同个线程内的同个 DDciFile static thread_local QHash> sharedDciFile; -static void doDeleteSharedDciFile(const QString &path, DDciFile *file) { +static void doDeleteSharedDciFile(const QString &path, DDciFile *file) +{ int count = sharedDciFile.remove(path); Q_ASSERT(count > 0); delete file; @@ -69,20 +70,18 @@ static DDciFileShared getDciFile(const QString &dciFilePath, bool usePath = true } DDciFileShared shared(usePath ? new DDciFile(dciFilePath) : new DDciFile(), - std::bind(doDeleteSharedDciFile, dciFilePath, - std::placeholders::_1)); + std::bind(doDeleteSharedDciFile, dciFilePath, std::placeholders::_1)); sharedDciFile[dciFilePath] = shared.toWeakRef(); return shared; } DDciFileEngineIterator::DDciFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters) -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) : QAbstractFileEngineIterator(nullptr, filters, nameFilters) #else : QAbstractFileEngineIterator(filters, nameFilters) #endif { - } #if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) @@ -93,7 +92,7 @@ QString DDciFileEngineIterator::next() } #endif -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) bool DDciFileEngineIterator::advance() #else bool DDciFileEngineIterator::hasNext() const @@ -101,8 +100,7 @@ bool DDciFileEngineIterator::hasNext() const { if (!file) { const auto paths = DDciFileEngine::resolvePath(path()); - if (paths.first.isEmpty() - || paths.second.isEmpty()) + if (paths.first.isEmpty() || paths.second.isEmpty()) return false; file = getDciFile(paths.first); @@ -122,7 +120,7 @@ bool DDciFileEngineIterator::hasNext() const } else if (fileType == DDciFile::Symlink) { if (filters.testFlag(QDir::NoSymLinks)) continue; - } else { // DDciFile::UnknowFile + } else { // DDciFile::UnknowFile continue; } @@ -131,7 +129,7 @@ bool DDciFileEngineIterator::hasNext() const continue; nextValid = i; -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) current = nextValid; #endif return true; @@ -200,8 +198,7 @@ bool DDciFileEngine::open(QIODevice::OpenMode openMode) } } - if ((openMode & QIODevice::ExistingOnly) - || !(openMode & QIODevice::WriteOnly)) { + if ((openMode & QIODevice::ExistingOnly) || !(openMode & QIODevice::WriteOnly)) { if (!file->exists(subfilePath)) { setError(QFile::OpenError, "The file is not exists"); return false; @@ -222,8 +219,7 @@ bool DDciFileEngine::open(QIODevice::OpenMode openMode) #endif // 不存在时尝试新建 - if (!file->exists(subfilePath) - && !file->writeFile(subfilePath, QByteArray())) { + if (!file->exists(subfilePath) && !file->writeFile(subfilePath, QByteArray())) { return false; } } @@ -513,24 +509,22 @@ QAbstractFileEngine::FileFlags DDciFileEngine::fileFlags(QAbstractFileEngine::Fi QString DDciFileEngine::fileName(QAbstractFileEngine::FileName file) const { switch (file) { - case AbsoluteName: - case CanonicalName: - case DefaultName: - return QDir::cleanPath(DCI_FILE_SCHEME + dciFilePath + subfilePath); - case AbsolutePathName: - return QDir::cleanPath(DCI_FILE_SCHEME + dciFilePath); - case BaseName: - return QFileInfo(subfilePath).baseName(); + case AbsoluteName: + case CanonicalName: + case DefaultName: + return QDir::cleanPath(DCI_FILE_SCHEME + dciFilePath + subfilePath); + case AbsolutePathName: + return QDir::cleanPath(DCI_FILE_SCHEME + dciFilePath); + case BaseName: + return QFileInfo(subfilePath).baseName(); #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) - case AbsoluteLinkTarget: + case AbsoluteLinkTarget: #else - case LinkName: + case LinkName: #endif - return this->file->type(subfilePath) == DDciFile::Symlink - ? this->file->symlinkTarget(subfilePath) - : QString(); - default: - break; + return this->file->type(subfilePath) == DDciFile::Symlink ? this->file->symlinkTarget(subfilePath) : QString(); + default: + break; } return QString(); @@ -545,8 +539,7 @@ void DDciFileEngine::setFileName(const QString &fullPath) subfilePath.clear(); const auto paths = resolvePath(fullPath, QString(), false); - if (paths.first.isEmpty() - || paths.second.isEmpty()) + if (paths.first.isEmpty() || paths.second.isEmpty()) return; dciFilePath = paths.first; @@ -566,19 +559,25 @@ QDateTime DDciFileEngine::fileTime(QAbstractFileEngine::FileTime time) const } #endif -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) -QAbstractFileEngine::IteratorUniquePtr DDciFileEngine::beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) +QAbstractFileEngine::IteratorUniquePtr +DDciFileEngine::beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) { return QAbstractFileEngine::IteratorUniquePtr(new DDciFileEngineIterator(filters, filterNames)); } #else DDciFileEngine::Iterator *DDciFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) +#endif { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + return QAbstractFileEngine::IteratorUniquePtr(new DDciFileEngineIterator(filters, filterNames)); +#else return new DDciFileEngineIterator(filters, filterNames); +#endif } #endif -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) QAbstractFileEngine::IteratorUniquePtr DDciFileEngine::endEntryList() #else DDciFileEngine::Iterator *DDciFileEngine::endEntryList() @@ -627,9 +626,7 @@ bool DDciFileEngine::forceSave(bool writeFile) const return flushToFile(&file, writeFile); } -QPair DDciFileEngine::resolvePath(const QString &fullPath, - const QString &realFilePath, - bool needRealFileExists) +QPair DDciFileEngine::resolvePath(const QString &fullPath, const QString &realFilePath, bool needRealFileExists) { if (!fullPath.startsWith(QStringLiteral(DCI_FILE_SCHEME) + realFilePath)) return {}; @@ -671,8 +668,8 @@ QPair DDciFileEngine::resolvePath(const QString &fullPath, return {}; subfilePath = QDir::cleanPath(formatFullPath.mid(schemeLength + dciFilePath.length())); - qCDebug(logFE(), "The DCI file path is: \"%s\", the subfile path is: \"%s\"", - qPrintable(dciFilePath), qPrintable(subfilePath)); + qCDebug( + logFE(), "The DCI file path is: \"%s\", the subfile path is: \"%s\"", qPrintable(dciFilePath), qPrintable(subfilePath)); Q_ASSERT(!subfilePath.isEmpty()); return qMakePair(dciFilePath, subfilePath); diff --git a/src/dci/private/ddcifileengine_p.h b/src/dci/private/ddcifileengine_p.h index 0730a69..a1ea33b 100644 --- a/src/dci/private/ddcifileengine_p.h +++ b/src/dci/private/ddcifileengine_p.h @@ -24,7 +24,7 @@ DCORE_BEGIN_NAMESPACE class DDciFileEngineHandler : public QAbstractFileEngineHandler { public: -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) std::unique_ptr create(const QString &fileName) const override; #else QAbstractFileEngine *create(const QString &fileName) const override; @@ -36,10 +36,11 @@ using DDciFileShared = QSharedPointer; class DDciFileEngineIterator : public QAbstractFileEngineIterator { friend class DDciFileEngine; + public: DDciFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) bool advance() override; #else QString next() override; @@ -58,6 +59,7 @@ class DDciFileEngineIterator : public QAbstractFileEngineIterator class DDciFileEngine : public QAbstractFileEngine { friend class DDciFileEngineIterator; + public: explicit DDciFileEngine(const QString &fullPath); ~DDciFileEngine(); @@ -121,8 +123,7 @@ class DDciFileEngine : public QAbstractFileEngine qint64 read(char *data, qint64 maxlen) override; qint64 write(const char *data, qint64 len) override; - bool extension(Extension extension, const ExtensionOption *option = 0, - ExtensionReturn *output = 0) override; + bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0) override; bool supportsExtension(Extension extension) const override; bool cloneTo(QAbstractFileEngine *target) override; @@ -137,9 +138,8 @@ class DDciFileEngine : public QAbstractFileEngine * 是 DCI 文件的内部路径。 * 函数返回的第一个数据是"真实文件路径"。 */ - static QPair resolvePath(const QString &fullPath, - const QString &realFilePath = QString(), - bool needRealFileExists = true); + static QPair + resolvePath(const QString &fullPath, const QString &realFilePath = QString(), bool needRealFileExists = true); DDciFileShared file; QString dciFilePath; @@ -150,5 +150,4 @@ class DDciFileEngine : public QAbstractFileEngine QBuffer *fileBuffer = nullptr; }; - DCORE_END_NAMESPACE diff --git a/src/filesystem/dcapfsfileengine.cpp b/src/filesystem/dcapfsfileengine.cpp index 65e160f..6d36f31 100644 --- a/src/filesystem/dcapfsfileengine.cpp +++ b/src/filesystem/dcapfsfileengine.cpp @@ -14,7 +14,7 @@ DCORE_BEGIN_NAMESPACE extern QString _d_cleanPath(const QString &path); extern bool _d_isSubFileOf(const QString &filePath, const QString &directoryPath); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) std::unique_ptr DCapFSFileEngineHandler::create(const QString &fileName) const { return std::unique_ptr(new DCapFSFileEngine(fileName)); @@ -34,14 +34,22 @@ static bool capDirIteraterHasNext(QAbstractFileEngineIterator *it) return ret; return DVtableHook::callOriginalFun(it, &QAbstractFileEngineIterator::hasNext); } +#endif +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) +std::unique_ptr DCapFSFileEngineHandler::create(const QString &fileName) const +#else QAbstractFileEngine *DCapFSFileEngineHandler::create(const QString &fileName) const +#endif { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + return std::unique_ptr(new DCapFSFileEngine(fileName)); +#else return new DCapFSFileEngine(fileName); +#endif } #endif - class DCapFSFileEnginePrivate : public DObjectPrivate { D_DECLARE_PUBLIC(DCapFSFileEngine) @@ -57,7 +65,6 @@ DCapFSFileEnginePrivate::DCapFSFileEnginePrivate(const QString &file, DCapFSFile : DObjectPrivate(qq) , file(file) { - } bool DCapFSFileEnginePrivate::canReadWrite(const QString &path) const @@ -75,20 +82,16 @@ bool DCapFSFileEnginePrivate::canReadWrite(const QString &path) const } auto paths = DCapManager::instance()->paths(); - return std::any_of(paths.cbegin(), paths.cend(), - std::bind(_d_isSubFileOf, target, std::placeholders::_1)); + return std::any_of(paths.cbegin(), paths.cend(), std::bind(_d_isSubFileOf, target, std::placeholders::_1)); } DCapFSFileEngine::DCapFSFileEngine(const QString &file) : QFSFileEngine(file) , DObject(*new DCapFSFileEnginePrivate(file, this)) { - } -DCapFSFileEngine::~DCapFSFileEngine() -{ -} +DCapFSFileEngine::~DCapFSFileEngine() {} #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) bool DCapFSFileEngine::open(QIODevice::OpenMode openMode, std::optional permissions) @@ -217,17 +220,23 @@ QStringList DCapFSFileEngine::entryList(QDir::Filters filters, const QStringList return QFSFileEngine::entryList(filters, filterNames); } -#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) -QAbstractFileEngine::IteratorUniquePtr DCapFSFileEngine::beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) +QAbstractFileEngine::IteratorUniquePtr +DCapFSFileEngine::beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) { auto ret = QFSFileEngine::beginEntryList(path, filters, filterNames); return ret; } #else QAbstractFileEngine::Iterator *DCapFSFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) +#endif { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + auto ret = QFSFileEngine::beginEntryList(path, filters, filterNames); +#else auto ret = QFSFileEngine::beginEntryList(filters, filterNames); DVtableHook::overrideVfptrFun(ret, &QAbstractFileEngineIterator::hasNext, &capDirIteraterHasNext); +#endif return ret; } #endif @@ -239,4 +248,3 @@ bool DCapFSFileEngine::canReadWrite(const QString &path) const } DCORE_END_NAMESPACE -