Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkcore
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#445
  • Loading branch information
deepin-ci-robot committed Dec 2, 2024
1 parent 21593f4 commit 2b2b97e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 47 deletions.
76 changes: 42 additions & 34 deletions src/dci/private/ddcifileengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ QAbstractFileEngine *DDciFileEngineHandler::create(const QString &fileName) cons
#else
DDciFileEngine *engine = new DDciFileEngine(fileName);
#endif

if (!engine->isValid()) {
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
delete engine;
Expand All @@ -56,8 +57,7 @@ QAbstractFileEngine *DDciFileEngineHandler::create(const QString &fileName) cons

// 共享同个线程内的同个 DDciFile
static thread_local QHash<QString, QWeakPointer<DDciFile>> 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;
Expand All @@ -70,7 +70,8 @@ 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;
}
Expand All @@ -82,6 +83,7 @@ DDciFileEngineIterator::DDciFileEngineIterator(QDir::Filters filters, const QStr
: QAbstractFileEngineIterator(filters, nameFilters)
#endif
{

}

#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
Expand All @@ -90,17 +92,16 @@ QString DDciFileEngineIterator::next()
current = nextValid;
return DDciFileEngineIterator::currentFileName();
}
#endif

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
bool DDciFileEngineIterator::advance()
#else
bool DDciFileEngineIterator::hasNext() const
#else
bool DDciFileEngineIterator::advance()

Check warning on line 98 in src/dci/private/ddcifileengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'advance' is never used.
#endif
{
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);
Expand All @@ -120,7 +121,7 @@ bool DDciFileEngineIterator::hasNext() const
} else if (fileType == DDciFile::Symlink) {
if (filters.testFlag(QDir::NoSymLinks))
continue;
} else { // DDciFile::UnknowFile
} else { // DDciFile::UnknowFile
continue;
}

Expand Down Expand Up @@ -198,7 +199,8 @@ 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;
Expand All @@ -219,7 +221,8 @@ 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;
}
}
Expand Down Expand Up @@ -509,22 +512,24 @@ 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();
Expand All @@ -539,7 +544,8 @@ 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;
Expand All @@ -560,17 +566,17 @@ 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)
{
return QAbstractFileEngine::IteratorUniquePtr(new DDciFileEngineIterator(filters, filterNames));
}
QAbstractFileEngine::IteratorUniquePtr DDciFileEngine::beginEntryList(const QString &path, QDir::Filters filters, const QStringList &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
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
QAbstractFileEngine::IteratorUniquePtr DDciFileEngine::endEntryList()
Expand Down Expand Up @@ -621,7 +627,9 @@ bool DDciFileEngine::forceSave(bool writeFile) const
return flushToFile(&file, writeFile);
}

QPair<QString, QString> DDciFileEngine::resolvePath(const QString &fullPath, const QString &realFilePath, bool needRealFileExists)
QPair<QString, QString> DDciFileEngine::resolvePath(const QString &fullPath,
const QString &realFilePath,
bool needRealFileExists)
{
if (!fullPath.startsWith(QStringLiteral(DCI_FILE_SCHEME) + realFilePath))
return {};
Expand Down Expand Up @@ -663,8 +671,8 @@ QPair<QString, QString> DDciFileEngine::resolvePath(const QString &fullPath, con
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);
Expand Down
18 changes: 10 additions & 8 deletions src/dci/private/ddcifileengine_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ using DDciFileShared = QSharedPointer<DDciFile>;
class DDciFileEngineIterator : public QAbstractFileEngineIterator
{
friend class DDciFileEngine;

public:
DDciFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters);

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
bool advance() override;
#else
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
QString next() override;
bool hasNext() const override;
#else
bool advance() override;
#endif

QString currentFileName() const override;
Expand All @@ -59,7 +58,6 @@ class DDciFileEngineIterator : public QAbstractFileEngineIterator
class DDciFileEngine : public QAbstractFileEngine
{
friend class DDciFileEngineIterator;

public:
explicit DDciFileEngine(const QString &fullPath);
~DDciFileEngine();
Expand Down Expand Up @@ -112,6 +110,7 @@ class DDciFileEngine : public QAbstractFileEngine
#endif

typedef DDciFileEngineIterator Iterator;

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
IteratorUniquePtr beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) override;
IteratorUniquePtr endEntryList() override;
Expand All @@ -123,7 +122,8 @@ 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;
Expand All @@ -138,8 +138,9 @@ class DDciFileEngine : public QAbstractFileEngine
* 是 DCI 文件的内部路径。
* 函数返回的第一个数据是"真实文件路径"。
*/
static QPair<QString, QString>
resolvePath(const QString &fullPath, const QString &realFilePath = QString(), bool needRealFileExists = true);
static QPair<QString, QString> resolvePath(const QString &fullPath,
const QString &realFilePath = QString(),
bool needRealFileExists = true);

DDciFileShared file;
QString dciFilePath;
Expand All @@ -150,4 +151,5 @@ class DDciFileEngine : public QAbstractFileEngine
QBuffer *fileBuffer = nullptr;
};


DCORE_END_NAMESPACE
10 changes: 5 additions & 5 deletions src/util/dvtablehook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ void DVtableHook::autoCleanVtable(const void *obj)
if (!fun)
return;

typedef void(*Destruct)(const void*);
Destruct destruct = reinterpret_cast<Destruct>(fun);
// call origin destruct function
destruct(obj);

if (hasVtable(obj)) {// 需要判断一下,有可能在执行析构函数时虚表已经被删除
// clean
clearGhostVtable(obj);
}

typedef void(*Destruct)(const void*);
Destruct destruct = reinterpret_cast<Destruct>(fun);
// call origin destruct function
destruct(obj);
}

bool DVtableHook::ensureVtable(const void *obj, std::function<void ()> destoryObjFun)
Expand Down

0 comments on commit 2b2b97e

Please sign in to comment.