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