summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-02-11 23:08:55 +0100
committerMax Kellermann <max@musicpd.org>2017-08-18 12:16:43 +0200
commit902fbb33471b07c3ab9bf62d13927f2db46e35f5 (patch)
tree6a85b281f1ba869b0a7a1bb429bc1d117d76d51b
parent9f16c798d02d23bccbf463b78bfb228ccc666e11 (diff)
db/LightDirectory: use std::chrono::system_clock::time_point
-rw-r--r--src/db/DatabasePrint.cxx2
-rw-r--r--src/db/LightDirectory.hxx7
-rw-r--r--src/db/plugins/ProxyDatabasePlugin.cxx9
-rw-r--r--src/db/plugins/simple/Directory.hxx5
-rw-r--r--src/db/plugins/simple/DirectorySave.cxx9
-rw-r--r--src/db/plugins/upnp/UpnpDatabasePlugin.cxx6
-rw-r--r--src/db/update/Archive.cxx4
-rw-r--r--src/db/update/Container.cxx4
-rw-r--r--src/db/update/Walk.cxx2
9 files changed, 30 insertions, 18 deletions
diff --git a/src/db/DatabasePrint.cxx b/src/db/DatabasePrint.cxx
index 9cb772cd5..fd8f72e18 100644
--- a/src/db/DatabasePrint.cxx
+++ b/src/db/DatabasePrint.cxx
@@ -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);
}
}
diff --git a/src/db/LightDirectory.hxx b/src/db/LightDirectory.hxx
index be17329a6..e066a1fbc 100644
--- a/src/db/LightDirectory.hxx
+++ b/src/db/LightDirectory.hxx
@@ -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 {
diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx
index 99c871758..f5c81bb9c 100644
--- a/src/db/plugins/ProxyDatabasePlugin.cxx
+++ b/src/db/plugins/ProxyDatabasePlugin.cxx
@@ -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)
diff --git a/src/db/plugins/simple/Directory.hxx b/src/db/plugins/simple/Directory.hxx
index f33edffa0..942c86115 100644
--- a/src/db/plugins/simple/Directory.hxx
+++ b/src/db/plugins/simple/Directory.hxx
@@ -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;
diff --git a/src/db/plugins/simple/DirectorySave.cxx b/src/db/plugins/simple/DirectorySave.cxx
index e1f83bf5b..d3f75a4d7 100644
--- a/src/db/plugins/simple/DirectorySave.cxx
+++ b/src/db/plugins/simple/DirectorySave.cxx
@@ -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
diff --git a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
index 2af522745..f40b70b87 100644
--- a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
+++ b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
@@ -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);
}
diff --git a/src/db/update/Archive.cxx b/src/db/update/Archive.cxx
index d6fb77d21..6004ed835 100644
--- a/src/db/update/Archive.cxx
+++ b/src/db/update/Archive.cxx
@@ -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);
diff --git a/src/db/update/Container.cxx b/src/db/update/Container.cxx
index 6069b172b..5d96b84d9 100644
--- a/src/db/update/Container.cxx
+++ b/src/db/update/Container.cxx
@@ -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;
}
diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx
index b18cda30f..c3af3f789 100644
--- a/src/db/update/Walk.cxx
+++ b/src/db/update/Walk.cxx
@@ -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;
}