Commit 78ca5491 authored by Max Kellermann's avatar Max Kellermann

db/Interface: GetUpdateStamp() returns std::chrono::system_clock::time_point

parent 4146475c
......@@ -28,6 +28,7 @@
#include "db/Stats.hxx"
#include "system/Clock.hxx"
#include "Log.hxx"
#include "util/ChronoUtil.hxx"
#include <chrono>
......@@ -101,10 +102,10 @@ db_stats_print(Response &r, const Database &db)
stats.song_count,
total_duration_s);
const time_t update_stamp = db.GetUpdateStamp();
if (update_stamp > 0)
const auto update_stamp = db.GetUpdateStamp();
if (!IsNegative(update_stamp))
r.Format("db_update: %lu\n",
(unsigned long)update_stamp);
(unsigned long)std::chrono::system_clock::to_time_t(update_stamp));
}
#endif
......
......@@ -24,7 +24,7 @@
#include "tag/Type.h"
#include "Compiler.h"
#include <time.h>
#include <chrono>
struct DatabasePlugin;
struct DatabaseStats;
......@@ -129,10 +129,10 @@ public:
/**
* Returns the time stamp of the last database update.
* Returns 0 if that is not not known/available.
* Returns a negative value if that is not not known/available.
*/
gcc_pure
virtual time_t GetUpdateStamp() const = 0;
virtual std::chrono::system_clock::time_point GetUpdateStamp() const = 0;
};
#endif
......@@ -89,7 +89,7 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
struct mpd_connection *connection;
/* this is mutable because GetStats() must be "const" */
mutable time_t update_stamp;
mutable std::chrono::system_clock::time_point update_stamp;
/**
* The libmpdclient idle mask that was removed from the other
......@@ -128,7 +128,7 @@ public:
unsigned Update(const char *uri_utf8, bool discard) override;
time_t GetUpdateStamp() const override {
std::chrono::system_clock::time_point GetUpdateStamp() const override {
return update_stamp;
}
......@@ -347,7 +347,7 @@ ProxyDatabase::Create(EventLoop &loop, DatabaseListener &listener,
void
ProxyDatabase::Open()
{
update_stamp = 0;
update_stamp = std::chrono::system_clock::time_point::min();
try {
Connect();
......@@ -818,7 +818,7 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection) const
if (stats2 == nullptr)
ThrowError(connection);
update_stamp = (time_t)mpd_stats_get_db_update_time(stats2);
update_stamp = std::chrono::system_clock::from_time_t(mpd_stats_get_db_update_time(stats2));
DatabaseStats stats;
stats.song_count = mpd_stats_get_number_of_songs(stats2);
......
......@@ -157,7 +157,7 @@ SimpleDatabase::Load()
FileInfo fi;
if (GetFileInfo(path, fi))
mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
mtime = fi.GetModificationTime();
}
void
......@@ -166,7 +166,7 @@ SimpleDatabase::Open()
assert(prefixed_light_song == nullptr);
root = Directory::NewRoot();
mtime = 0;
mtime = std::chrono::system_clock::time_point::min();
#ifndef NDEBUG
borrowed_song_count = 0;
......@@ -358,7 +358,7 @@ SimpleDatabase::Save()
FileInfo fi;
if (GetFileInfo(path, fi))
mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
mtime = fi.GetModificationTime();
}
void
......
......@@ -50,7 +50,7 @@ class SimpleDatabase : public Database {
Directory *root;
time_t mtime;
std::chrono::system_clock::time_point mtime;
/**
* A buffer for GetSong() when prefixing the #LightSong
......@@ -88,7 +88,7 @@ public:
* Returns true if there is a valid database file on the disk.
*/
bool FileExists() const {
return mtime > 0;
return mtime >= std::chrono::system_clock::time_point(std::chrono::system_clock::duration::zero());
}
/**
......@@ -125,7 +125,7 @@ public:
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
time_t GetUpdateStamp() const override {
std::chrono::system_clock::time_point GetUpdateStamp() const override {
return mtime;
}
......
......@@ -94,8 +94,8 @@ public:
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
time_t GetUpdateStamp() const override {
return 0;
std::chrono::system_clock::time_point GetUpdateStamp() const override {
return std::chrono::system_clock::time_point::min();
}
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment