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;
|
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{};
|
auto *newEntry = new (std::nothrow) DesktopEntry{};
|
||||||
if (newEntry == nullptr) {
|
if (newEntry == nullptr) {
|
||||||
qCritical() << "new DesktopEntry failed.";
|
qCritical() << "new DesktopEntry failed.";
|
||||||
|
@ -364,7 +364,7 @@ std::optional<DesktopFile> DesktopFile::searchDesktopFileById(const QString &app
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DesktopFile::modified(std::size_t time) const noexcept
|
bool DesktopFile::modified(qint64 time) const noexcept
|
||||||
{
|
{
|
||||||
return time != m_mtime;
|
return time != m_mtime;
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ struct DesktopFile
|
|||||||
[[nodiscard]] QFile *sourceFile() const noexcept { return &sourceFileRef(); };
|
[[nodiscard]] QFile *sourceFile() const noexcept { return &sourceFileRef(); };
|
||||||
[[nodiscard]] QFile &sourceFileRef() const noexcept { return *m_fileSource; };
|
[[nodiscard]] QFile &sourceFileRef() const noexcept { return *m_fileSource; };
|
||||||
[[nodiscard]] const QString &desktopId() const noexcept { return m_desktopId; }
|
[[nodiscard]] const QString &desktopId() const noexcept { return m_desktopId; }
|
||||||
[[nodiscard]] bool modified(std::size_t time) const noexcept;
|
[[nodiscard]] bool modified(qint64 time) const noexcept;
|
||||||
[[nodiscard]] std::size_t createTime() const noexcept { return m_ctime; }
|
[[nodiscard]] qint64 createTime() const noexcept { return m_ctime; }
|
||||||
|
|
||||||
static std::optional<DesktopFile> searchDesktopFileById(const QString &appId, DesktopErrorCode &err) noexcept;
|
static std::optional<DesktopFile> searchDesktopFileById(const QString &appId, DesktopErrorCode &err) noexcept;
|
||||||
static std::optional<DesktopFile> searchDesktopFileByPath(const QString &desktopFilePath, 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;
|
static std::optional<DesktopFile> createTemporaryDesktopFile(std::unique_ptr<QFile> temporaryFile) noexcept;
|
||||||
|
|
||||||
private:
|
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_mtime(mtime)
|
||||||
, m_ctime(ctime)
|
, m_ctime(ctime)
|
||||||
, m_fileSource(std::move(source))
|
, m_fileSource(std::move(source))
|
||||||
@ -64,8 +64,8 @@ private:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t m_mtime;
|
qint64 m_mtime;
|
||||||
std::size_t m_ctime;
|
qint64 m_ctime;
|
||||||
std::unique_ptr<QFile> m_fileSource{nullptr};
|
std::unique_ptr<QFile> m_fileSource{nullptr};
|
||||||
QString m_desktopId{""};
|
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;
|
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.
|
inline FileTimeInfo getFileTimeInfo(const QFileInfo &file)
|
||||||
if (auto ret = stat(file.absoluteFilePath().toLocal8Bit().constData(), &buf); ret == -1) {
|
{
|
||||||
qWarning() << "get file" << file.absoluteFilePath() << "state failed:" << std::strerror(errno);
|
auto mtime = file.lastModified().toMSecsSinceEpoch();
|
||||||
return std::make_tuple(0, 0, 0);
|
auto atime = file.lastRead().toMSecsSinceEpoch();
|
||||||
}
|
auto ctime = file.birthTime().toMSecsSinceEpoch();
|
||||||
|
return {mtime, ctime, atime};
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user