Skip to content

Commit

Permalink
fix: [io]Peripheral paste the same name directory selection coexisten…
Browse files Browse the repository at this point in the history
…ce, file sorting is not correct

Asynchronous file information is created when a file is received from the monitor to create a file, multiple queries are executed, and caching of file attributes is performed in multiple threads, but the corresponding dfmfileinfo is different. So accessing file attributes at this point is incorrect.

Log: Peripheral paste the same name directory selection coexistence, file sorting is not correct need to refresh manually
Bug: https://pms.uniontech.com/bug-view-217143.html
  • Loading branch information
liyigang1 committed Aug 31, 2023
1 parent 35702ab commit f9bc692
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/dfm-base/file/local/asyncfileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,20 @@ void AsyncFileInfo::removeNotifyUrl(const QUrl &url, const QString &infoPtr)
d->notifyUrls.remove(url, infoPtr);
}

void AsyncFileInfo::cacheAsyncAttributes()
bool AsyncFileInfo::cacheAsyncAttributes()
{
assert(qApp->thread() != QThread::currentThread());
auto dfmFileInfo = d->dfmFileInfo;
if (d->tokenKey != quintptr(dfmFileInfo.data()))
return false;

if (d->cacheing)
return false;
if (!d->cacheing)
d->cacheing = true;
d->cacheAllAttributes();
d->cacheing = false;
return true;
}

bool AsyncFileInfo::asyncQueryDfmFileInfo(int ioPriority, FileInfo::initQuerierAsyncCallback func, void *userData)
Expand All @@ -545,7 +552,7 @@ bool AsyncFileInfo::asyncQueryDfmFileInfo(int ioPriority, FileInfo::initQuerierA
if (!d->dfmFileInfo) {
d->cacheing = false;
return false;
}
}

d->dfmFileInfo->initQuerierAsync(ioPriority, func, userData);
d->cacheing = false;
Expand Down Expand Up @@ -575,6 +582,7 @@ void AsyncFileInfoPrivate::init(const QUrl &url, QSharedPointer<DFMIO::DFileInfo
if (dfileInfo) {
notInit = true;
dfmFileInfo = dfileInfo;
tokenKey = quintptr(dfmFileInfo.data());
return;
}

Expand All @@ -584,6 +592,7 @@ void AsyncFileInfoPrivate::init(const QUrl &url, QSharedPointer<DFMIO::DFileInfo
qWarning("Failed, dfm-io use factory create fileinfo");
abort();
}
tokenKey = quintptr(dfmFileInfo.data());
}

QMimeType AsyncFileInfoPrivate::mimeTypes(const QString &filePath, QMimeDatabase::MatchMode mode, const QString &inod, const bool isGvfs)
Expand Down
2 changes: 1 addition & 1 deletion src/dfm-base/file/local/asyncfileinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class AsyncFileInfo : public FileInfo
QMultiMap<QUrl, QString> notifyUrls() const;
void setNotifyUrl(const QUrl &url, const QString &infoPtr);
void removeNotifyUrl(const QUrl &url, const QString &infoPtr);
void cacheAsyncAttributes();
bool cacheAsyncAttributes();
bool asyncQueryDfmFileInfo(int ioPriority = 0, initQuerierAsyncCallback func = nullptr, void *userData = nullptr);
};
}
Expand Down
1 change: 1 addition & 0 deletions src/dfm-base/file/local/private/asyncfileinfo_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AsyncFileInfoPrivate
QMap<AsyncFileInfo::AsyncAttributeID, QVariant> cacheAsyncAttributes;
QReadWriteLock notifyLock;
QMultiMap<QUrl, QString> notifyUrls;
quint64 tokenKey{0};
AsyncFileInfo *const q;

public:
Expand Down
6 changes: 3 additions & 3 deletions src/dfm-base/utils/fileinfohelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ void FileInfoHelper::threadHandleDfmFileInfo(const QSharedPointer<FileInfo> dfil
return;

auto asyncInfo = dfileInfo.dynamicCast<AsyncFileInfo>();
if (!asyncInfo) {
if (asyncInfo.isNull())
return;
}

asyncInfo->cacheAsyncAttributes();
if (!asyncInfo->cacheAsyncAttributes())
return;

emit fileRefreshFinished(dfileInfo->fileUrl(), QString::number(quintptr(dfileInfo.data()), 16), false);

Expand Down
2 changes: 1 addition & 1 deletion tests/dfm-base/file/local/ut_localfilediriterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST_F(UT_LocalFileDirIterator, testLocalFileIterator)
stub.set_lamda(&FileUtils::isLocalDevice, []{ __DBG_STUB_INVOKE__ return false;});
typedef FileInfoPointer (*TransfromInfo)(const QString &, FileInfoPointer);
stub.set_lamda(static_cast<TransfromInfo>(&dfmbase::InfoFactory::transfromInfo), []{ __DBG_STUB_INVOKE__ return nullptr;});
stub.set_lamda(&AsyncFileInfo::cacheAsyncAttributes, []{ __DBG_STUB_INVOKE__ });
stub.set_lamda(&AsyncFileInfo::cacheAsyncAttributes, []{ __DBG_STUB_INVOKE__ return true;});
EXPECT_TRUE(iterator->fileInfo().isNull());

EXPECT_EQ(fileUrl, iterator->fileUrl());
Expand Down

0 comments on commit f9bc692

Please sign in to comment.