Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 30 additions & 61 deletions src/dfm-io/dfm-io/dfileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
#include <QVariant>
#include <QPointer>
#include <QTimer>
#include <QDebug>

Check warning on line 15 in src/dfm-io/dfm-io/dfileinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in src/dfm-io/dfm-io/dfileinfo.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QThread>

Check warning on line 16 in src/dfm-io/dfm-io/dfileinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QThread> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 16 in src/dfm-io/dfm-io/dfileinfo.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QThread> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <sys/stat.h>
#include <fcntl.h>

Check warning on line 18 in src/dfm-io/dfm-io/dfileinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <fcntl.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 18 in src/dfm-io/dfm-io/dfileinfo.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <fcntl.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <execinfo.h>

Check warning on line 19 in src/dfm-io/dfm-io/dfileinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <execinfo.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 19 in src/dfm-io/dfm-io/dfileinfo.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <execinfo.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

USING_IO_NAMESPACE

Expand Down Expand Up @@ -281,6 +280,24 @@
g_file_query_info_async(this->gfile, attributes, GFileQueryInfoFlags(flag), ioPriority, gcancellable, queryInfoAsyncCallback, dataOp);
}

bool DFileInfoPrivate::ensureStatxCached() const
{
if (statxCached)
return statxValid;

statxCached = true;

const QUrl &url = q->uri();
if (!url.isLocalFile())
return false;

unsigned mask = STATX_BASIC_STATS | STATX_BTIME;
int ret = statx(AT_FDCWD, url.path().toStdString().data(),
AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, mask, &statxBuf);
statxValid = (ret == 0);
return statxValid;
}

QVariant DFileInfoPrivate::attributesBySelf(DFileInfo::AttributeID id)
{
QVariant retValue;
Expand All @@ -295,18 +312,10 @@
return QVariant();
uint64_t ret = g_file_info_get_attribute_uint64(gfileinfo, key.c_str());
if (ret == 0) {
struct statx statxBuffer;
unsigned mask = STATX_BASIC_STATS | STATX_BTIME;
const QUrl &url = q->uri();
if (!url.isLocalFile())
return QVariant();
int ret = statx(AT_FDCWD, url.path().toStdString().data(), AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, mask, &statxBuffer);
if (ret != 0)
if (!ensureStatxCached())
return QVariant();

return statxBuffer.stx_btime.tv_sec > 0
? quint64(statxBuffer.stx_btime.tv_sec)
: quint64(statxBuffer.stx_ctime.tv_sec);
return quint64(statxBuf.stx_btime.tv_sec);
}
return qulonglong(ret);
}
Expand All @@ -316,18 +325,10 @@
return QVariant();
uint32_t ret = g_file_info_get_attribute_uint32(gfileinfo, key.c_str());
if (ret == 0) {
struct statx statxBuffer;
unsigned mask = STATX_BASIC_STATS | STATX_BTIME;
const QUrl &url = q->uri();
if (!url.isLocalFile())
return QVariant();
int ret = statx(AT_FDCWD, url.path().toStdString().data(), AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, mask, &statxBuffer);
if (ret != 0)
if (!ensureStatxCached())
return QVariant();

return statxBuffer.stx_btime.tv_nsec > 0
? statxBuffer.stx_btime.tv_nsec / 1000000
: statxBuffer.stx_ctime.tv_nsec / 1000000;
return statxBuf.stx_btime.tv_nsec / 1000000;
}
return QVariant(ret);
}
Expand All @@ -337,18 +338,10 @@
return QVariant();
uint64_t ret = g_file_info_get_attribute_uint64(gfileinfo, key.c_str());
if (ret == 0) {
struct statx statxBuffer;
unsigned mask = STATX_BASIC_STATS | STATX_BTIME;
const QUrl &url = q->uri();
if (!url.isLocalFile())
return QVariant();
int ret = statx(AT_FDCWD, url.path().toStdString().data(), AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, mask, &statxBuffer);
if (ret != 0)
if (!ensureStatxCached())
return QVariant();

return statxBuffer.stx_mtime.tv_sec > 0
? quint64(statxBuffer.stx_mtime.tv_sec)
: quint64(statxBuffer.stx_ctime.tv_sec);
return quint64(statxBuf.stx_mtime.tv_sec);
}
return qulonglong(ret);
}
Expand All @@ -358,18 +351,10 @@
return QVariant();
uint32_t ret = g_file_info_get_attribute_uint32(gfileinfo, key.c_str());
if (ret == 0) {
struct statx statxBuffer;
unsigned mask = STATX_BASIC_STATS | STATX_BTIME;
const QUrl &url = q->uri();
if (!url.isLocalFile())
return QVariant();
int ret = statx(AT_FDCWD, url.path().toStdString().data(), AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, mask, &statxBuffer);
if (ret != 0)
if (!ensureStatxCached())
return QVariant();

return statxBuffer.stx_mtime.tv_nsec > 0
? statxBuffer.stx_mtime.tv_nsec / 1000000
: statxBuffer.stx_ctime.tv_nsec / 1000000;
return statxBuf.stx_mtime.tv_nsec / 1000000;
}
return QVariant(ret);
}
Expand All @@ -379,18 +364,10 @@
return QVariant();
uint64_t ret = g_file_info_get_attribute_uint64(gfileinfo, key.c_str());
if (ret == 0) {
struct statx statxBuffer;
unsigned mask = STATX_BASIC_STATS | STATX_BTIME;
const QUrl &url = q->uri();
if (!url.isLocalFile())
return QVariant();
int ret = statx(AT_FDCWD, url.path().toStdString().data(), AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, mask, &statxBuffer);
if (ret != 0)
if (!ensureStatxCached())
return QVariant();

return statxBuffer.stx_atime.tv_sec > 0
? quint64(statxBuffer.stx_atime.tv_sec)
: quint64(statxBuffer.stx_ctime.tv_sec);
return quint64(statxBuf.stx_atime.tv_sec);
}
return qulonglong(ret);
}
Expand All @@ -400,18 +377,10 @@
return QVariant();
uint32_t ret = g_file_info_get_attribute_uint32(gfileinfo, key.c_str());
if (ret == 0) {
struct statx statxBuffer;
unsigned mask = STATX_BASIC_STATS | STATX_BTIME;
const QUrl &url = q->uri();
if (!url.isLocalFile())
return QVariant();
int ret = statx(AT_FDCWD, url.path().toStdString().data(), AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, mask, &statxBuffer);
if (ret != 0)
if (!ensureStatxCached())
return QVariant();

return statxBuffer.stx_atime.tv_nsec > 0
? statxBuffer.stx_atime.tv_nsec / 1000000
: statxBuffer.stx_ctime.tv_nsec / 1000000;
return statxBuf.stx_atime.tv_nsec / 1000000;
}
return QVariant(ret);
}
Expand Down
7 changes: 7 additions & 0 deletions src/dfm-io/dfm-io/private/dfileinfo_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

#include <gio/gio.h>

#include <unordered_map>

Check warning on line 20 in src/dfm-io/dfm-io/private/dfileinfo_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unordered_map> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 20 in src/dfm-io/dfm-io/private/dfileinfo_p.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <unordered_map> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string>

Check warning on line 21 in src/dfm-io/dfm-io/private/dfileinfo_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <string> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 21 in src/dfm-io/dfm-io/private/dfileinfo_p.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <string> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <sys/stat.h>

Check warning on line 22 in src/dfm-io/dfm-io/private/dfileinfo_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sys/stat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 22 in src/dfm-io/dfm-io/private/dfileinfo_p.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <sys/stat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

BEGIN_IO_NAMESPACE

Expand Down Expand Up @@ -55,6 +56,7 @@
QVariant attributesBySelf(DFileInfo::AttributeID id);
QVariant attributesFromUrl(DFileInfo::AttributeID id);
void checkAndResetCancel();
[[nodiscard]] bool ensureStatxCached() const;

[[nodiscard]] DFileFuture *initQuerierAsync(int ioPriority, QObject *parent = nullptr) const;
[[nodiscard]] QFuture<void> refreshAsync();
Expand Down Expand Up @@ -94,6 +96,11 @@
std::atomic_bool stoped { false };
std::atomic_bool fileExists { false };
QMap<DFileInfo::AttributeID, QVariant> caches;

// statx 缓存:6 个时间属性 case 共享一次 statx 调用,避免重复系统调用
mutable struct statx statxBuf {};
mutable bool statxCached { false };
mutable bool statxValid { false };
std::atomic_bool cacheing { false };
std::atomic_bool refreshing { false };
QMutex mutex;
Expand Down
Loading