refact: use QFileInfo to get File's timeInfo
Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
dc96c21c7d
commit
3f38233306
@ -328,9 +328,9 @@ void ApplicationManager1Service::updateApplication(const QSharedPointer<Applicat
|
||||
return;
|
||||
}
|
||||
|
||||
auto mtime = getFileTimeInfo(QFileInfo{desktopFile.sourceFileRef()});
|
||||
auto timeInfo = getFileTimeInfo(QFileInfo{desktopFile.sourceFileRef()});
|
||||
|
||||
if (destApp->desktopFileSource().modified(std::get<1>(mtime))) {
|
||||
if (destApp->desktopFileSource().modified(timeInfo.mtime)) {
|
||||
auto *newEntry = new (std::nothrow) DesktopEntry{};
|
||||
if (newEntry == nullptr) {
|
||||
qCritical() << "new DesktopEntry failed.";
|
||||
|
@ -238,9 +238,9 @@ bool DesktopEntry::checkMainEntryValidation() const noexcept
|
||||
if (type == it->end()) {
|
||||
qWarning() << "No Type.";
|
||||
for (auto tmp = it->constKeyValueBegin(); tmp != it->constKeyValueEnd(); ++tmp) {
|
||||
const auto& [k,v] = *tmp;
|
||||
const auto &[k, v] = *tmp;
|
||||
qInfo() << "keyName:" << k;
|
||||
for (auto valIt = v.constKeyValueBegin() ; valIt != v.constKeyValueEnd(); ++valIt) {
|
||||
for (auto valIt = v.constKeyValueBegin(); valIt != v.constKeyValueEnd(); ++valIt) {
|
||||
const auto &[key, value] = *valIt;
|
||||
qInfo() << key << value;
|
||||
}
|
||||
@ -364,7 +364,7 @@ std::optional<DesktopFile> DesktopFile::searchDesktopFileById(const QString &app
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool DesktopFile::modified(std::size_t time) const noexcept
|
||||
bool DesktopFile::modified(qint64 time) const noexcept
|
||||
{
|
||||
return time != m_mtime;
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ struct DesktopFile
|
||||
[[nodiscard]] QFile *sourceFile() const noexcept { return &sourceFileRef(); };
|
||||
[[nodiscard]] QFile &sourceFileRef() const noexcept { return *m_fileSource; };
|
||||
[[nodiscard]] const QString &desktopId() const noexcept { return m_desktopId; }
|
||||
[[nodiscard]] bool modified(std::size_t time) const noexcept;
|
||||
[[nodiscard]] std::size_t createTime() const noexcept { return m_ctime; }
|
||||
[[nodiscard]] bool modified(qint64 time) const noexcept;
|
||||
[[nodiscard]] qint64 createTime() const noexcept { return m_ctime; }
|
||||
|
||||
static std::optional<DesktopFile> searchDesktopFileById(const QString &appId, DesktopErrorCode &err) noexcept;
|
||||
static std::optional<DesktopFile> searchDesktopFileByPath(const QString &desktopFilePath, DesktopErrorCode &err) noexcept;
|
||||
@ -56,7 +56,7 @@ struct DesktopFile
|
||||
static std::optional<DesktopFile> createTemporaryDesktopFile(std::unique_ptr<QFile> temporaryFile) noexcept;
|
||||
|
||||
private:
|
||||
DesktopFile(std::unique_ptr<QFile> source, QString fileId, std::size_t mtime, std::size_t ctime)
|
||||
DesktopFile(std::unique_ptr<QFile> source, QString fileId, qint64 mtime, qint64 ctime)
|
||||
: m_mtime(mtime)
|
||||
, m_ctime(ctime)
|
||||
, m_fileSource(std::move(source))
|
||||
@ -64,8 +64,8 @@ private:
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t m_mtime;
|
||||
std::size_t m_ctime;
|
||||
qint64 m_mtime;
|
||||
qint64 m_ctime;
|
||||
std::unique_ptr<QFile> m_fileSource{nullptr};
|
||||
QString m_desktopId{""};
|
||||
};
|
||||
|
26
src/global.h
26
src/global.h
@ -468,23 +468,19 @@ ObjectMap dumpDBusObject(const QMap<QDBusObjectPath, QSharedPointer<T>> &map)
|
||||
return objs;
|
||||
}
|
||||
|
||||
inline std::tuple<std::size_t, std::size_t, std::size_t> getFileTimeInfo(const QFileInfo &file)
|
||||
struct FileTimeInfo
|
||||
{
|
||||
struct stat buf;
|
||||
qint64 mtime;
|
||||
qint64 ctime;
|
||||
qint64 atime;
|
||||
};
|
||||
|
||||
// TODO: use QFileInfo get timeInfo, and return a custom time structure.
|
||||
if (auto ret = stat(file.absoluteFilePath().toLocal8Bit().constData(), &buf); ret == -1) {
|
||||
qWarning() << "get file" << file.absoluteFilePath() << "state failed:" << std::strerror(errno);
|
||||
return std::make_tuple(0, 0, 0);
|
||||
}
|
||||
|
||||
constexpr std::size_t secToNano = 1e9;
|
||||
|
||||
auto mtime = buf.st_mtim.tv_sec * secToNano + buf.st_mtim.tv_nsec;
|
||||
auto ctime = buf.st_ctim.tv_sec * secToNano + buf.st_ctim.tv_nsec;
|
||||
auto atime = buf.st_atim.tv_sec * secToNano + buf.st_atim.tv_nsec;
|
||||
|
||||
return std::make_tuple(ctime, mtime, atime);
|
||||
inline FileTimeInfo getFileTimeInfo(const QFileInfo &file)
|
||||
{
|
||||
auto mtime = file.lastModified().toMSecsSinceEpoch();
|
||||
auto atime = file.lastRead().toMSecsSinceEpoch();
|
||||
auto ctime = file.birthTime().toMSecsSinceEpoch();
|
||||
return {mtime, ctime, atime};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user