Commit 902fbb33 authored by Max Kellermann's avatar Max Kellermann

db/LightDirectory: use std::chrono::system_clock::time_point

parent 9f16c798
......@@ -66,7 +66,7 @@ PrintDirectoryFull(Response &r, bool base, const LightDirectory &directory)
if (!directory.IsRoot()) {
PrintDirectoryURI(r, base, directory);
if (directory.mtime > 0)
if (!IsNegative(directory.mtime))
time_print(r, "Last-Modified", directory.mtime);
}
}
......
......@@ -39,13 +39,14 @@ struct Tag;
struct LightDirectory {
const char *uri;
time_t mtime;
std::chrono::system_clock::time_point mtime;
constexpr LightDirectory(const char *_uri, time_t _mtime)
constexpr LightDirectory(const char *_uri,
std::chrono::system_clock::time_point _mtime)
:uri(_uri), mtime(_mtime) {}
static constexpr LightDirectory Root() noexcept {
return LightDirectory("", 0);
return LightDirectory("", std::chrono::system_clock::time_point::min());
}
bool IsRoot() const noexcept {
......
......@@ -562,10 +562,13 @@ Visit(struct mpd_connection *connection,
VisitPlaylist visit_playlist)
{
const char *path = mpd_directory_get_path(directory);
std::chrono::system_clock::time_point mtime =
std::chrono::system_clock::time_point::min();
#if LIBMPDCLIENT_CHECK_VERSION(2,9,0)
time_t mtime = mpd_directory_get_last_modified(directory);
#else
time_t mtime = 0;
time_t _mtime = mpd_directory_get_last_modified(directory);
if (_mtime > 0)
mtime = std::chrono::system_clock::from_time_t(_mtime);
#endif
if (visit_directory)
......
......@@ -85,7 +85,10 @@ struct Directory {
PlaylistVector playlists;
Directory *const parent;
time_t mtime = 0;
std::chrono::system_clock::time_point mtime =
std::chrono::system_clock::time_point::min();
uint64_t inode = 0, device = 0;
const std::string path;
......
......@@ -26,6 +26,7 @@
#include "PlaylistDatabase.hxx"
#include "fs/io/TextFile.hxx"
#include "fs/io/BufferedOutputStream.hxx"
#include "util/ChronoUtil.hxx"
#include "util/StringCompare.hxx"
#include "util/NumberParser.hxx"
#include "util/RuntimeError.hxx"
......@@ -74,9 +75,9 @@ directory_save(BufferedOutputStream &os, const Directory &directory)
if (type != nullptr)
os.Format(DIRECTORY_TYPE "%s\n", type);
if (directory.mtime != 0)
if (!IsNegative(directory.mtime))
os.Format(DIRECTORY_MTIME "%lu\n",
(unsigned long)directory.mtime);
(unsigned long)std::chrono::system_clock::to_time_t(directory.mtime));
os.Format("%s%s\n", DIRECTORY_BEGIN, directory.GetPath());
}
......@@ -102,7 +103,9 @@ ParseLine(Directory &directory, const char *line)
{
const char *p;
if ((p = StringAfterPrefix(line, DIRECTORY_MTIME))) {
directory.mtime = ParseUint64(p);
const auto mtime = ParseUint64(p);
if (mtime > 0)
directory.mtime = std::chrono::system_clock::from_time_t(mtime);
} else if ((p = StringAfterPrefix(line, DIRECTORY_TYPE))) {
directory.device = ParseTypeString(p);
} else
......
......@@ -477,7 +477,8 @@ VisitObject(const UPnPDirObject &object, const char *uri,
case UPnPDirObject::Type::CONTAINER:
if (visit_directory)
visit_directory(LightDirectory(uri, 0));
visit_directory(LightDirectory(uri,
std::chrono::system_clock::time_point::min()));
break;
case UPnPDirObject::Type::ITEM:
......@@ -582,7 +583,8 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
if (vpath.empty()) {
for (const auto &server : discovery->GetDirectories()) {
if (visit_directory) {
const LightDirectory d(server.getFriendlyName(), 0);
const LightDirectory d(server.getFriendlyName(),
std::chrono::system_clock::time_point::min());
visit_directory(d);
}
......
......@@ -137,7 +137,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
{
Directory *directory = LockFindChild(parent, name);
if (directory != nullptr && directory->mtime == std::chrono::system_clock::to_time_t(info.mtime) &&
if (directory != nullptr && directory->mtime == info.mtime &&
!walk_discard)
/* MPD has already scanned the archive, and it hasn't
changed since - don't consider updating it */
......@@ -173,7 +173,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
directory->device = DEVICE_INARCHIVE;
}
directory->mtime = std::chrono::system_clock::to_time_t(info.mtime);
directory->mtime = info.mtime;
UpdateArchiveVisitor visitor(*this, *file, directory);
file->Visit(visitor);
......
......@@ -43,7 +43,7 @@ UpdateWalk::MakeDirectoryIfModified(Directory &parent, const char *name,
if (directory->IsMount())
return nullptr;
if (directory->mtime == std::chrono::system_clock::to_time_t(info.mtime) && !walk_discard) {
if (directory->mtime == info.mtime && !walk_discard) {
/* not modified */
return nullptr;
}
......@@ -53,7 +53,7 @@ UpdateWalk::MakeDirectoryIfModified(Directory &parent, const char *name,
}
directory = parent.MakeChild(name);
directory->mtime = std::chrono::system_clock::to_time_t(info.mtime);
directory->mtime = info.mtime;
return directory;
}
......
......@@ -382,7 +382,7 @@ UpdateWalk::UpdateDirectory(Directory &directory,
UpdateDirectoryChild(directory, child_exclude_list, name_utf8, info2);
}
directory.mtime = std::chrono::system_clock::to_time_t(info.mtime);
directory.mtime = info.mtime;
return true;
}
......
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