db/PlaylistInfo: use std::chrono::system_clock::time_point
This commit is contained in:
parent
9d0a71f245
commit
6f37f5752b
|
@ -23,6 +23,7 @@
|
|||
#include "fs/io/TextFile.hxx"
|
||||
#include "fs/io/BufferedOutputStream.hxx"
|
||||
#include "util/StringStrip.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <string.h>
|
||||
|
@ -31,17 +32,19 @@
|
|||
void
|
||||
playlist_vector_save(BufferedOutputStream &os, const PlaylistVector &pv)
|
||||
{
|
||||
for (const PlaylistInfo &pi : pv)
|
||||
os.Format(PLAYLIST_META_BEGIN "%s\n"
|
||||
"mtime: %li\n"
|
||||
"playlist_end\n",
|
||||
pi.name.c_str(), (long)pi.mtime);
|
||||
for (const PlaylistInfo &pi : pv) {
|
||||
os.Format(PLAYLIST_META_BEGIN "%s\n", pi.name.c_str());
|
||||
if (!IsNegative(pi.mtime))
|
||||
os.Format("mtime: %li\n",
|
||||
(long)std::chrono::system_clock::to_time_t(pi.mtime));
|
||||
os.Write("playlist_end\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
playlist_metadata_load(TextFile &file, PlaylistVector &pv, const char *name)
|
||||
{
|
||||
PlaylistInfo pm(name, 0);
|
||||
PlaylistInfo pm(name);
|
||||
|
||||
char *line, *colon;
|
||||
const char *value;
|
||||
|
@ -57,7 +60,7 @@ playlist_metadata_load(TextFile &file, PlaylistVector &pv, const char *name)
|
|||
value = StripLeft(colon);
|
||||
|
||||
if (strcmp(line, "mtime") == 0)
|
||||
pm.mtime = strtol(value, nullptr, 10);
|
||||
pm.mtime = std::chrono::system_clock::from_time_t(strtol(value, nullptr, 10));
|
||||
else
|
||||
throw FormatRuntimeError("unknown line in db: %s",
|
||||
line);
|
||||
|
|
|
@ -148,7 +148,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
|
|||
return false;
|
||||
|
||||
info.name = std::move(name_utf8);
|
||||
info.mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
|
||||
info.mtime = fi.GetModificationTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "decoder/DecoderPrint.hxx"
|
||||
#include "ls.hxx"
|
||||
#include "mixer/Volume.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
#include "util/StringAPI.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
|
@ -63,7 +64,7 @@ print_spl_list(Response &r, const PlaylistVector &list)
|
|||
for (const auto &i : list) {
|
||||
r.Format("playlist: %s\n", i.name.c_str());
|
||||
|
||||
if (i.mtime > 0)
|
||||
if (!IsNegative(i.mtime))
|
||||
time_print(r, "Last-Modified", i.mtime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "fs/AllocatedPath.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
|
||||
bool
|
||||
playlist_commands_available() noexcept
|
||||
|
@ -50,7 +51,7 @@ print_spl_list(Response &r, const PlaylistVector &list)
|
|||
for (const auto &i : list) {
|
||||
r.Format("playlist: %s\n", i.name.c_str());
|
||||
|
||||
if (i.mtime > 0)
|
||||
if (!IsNegative(i.mtime))
|
||||
time_print(r, "Last-Modified", i.mtime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "PlaylistInfo.hxx"
|
||||
#include "Interface.hxx"
|
||||
#include "fs/Traits.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
@ -134,7 +135,7 @@ PrintPlaylistFull(Response &r, bool base,
|
|||
print_playlist_in_directory(r, base,
|
||||
&directory, playlist.name.c_str());
|
||||
|
||||
if (playlist.mtime > 0)
|
||||
if (!IsNegative(playlist.mtime))
|
||||
time_print(r, "Last-Modified", playlist.mtime);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
#include "Compiler.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <chrono>
|
||||
|
||||
/**
|
||||
* A directory entry pointing to a playlist file.
|
||||
|
@ -36,7 +35,12 @@ struct PlaylistInfo {
|
|||
*/
|
||||
std::string name;
|
||||
|
||||
time_t mtime;
|
||||
/**
|
||||
* The time stamp of the last file modification. A negative
|
||||
* value means that this is unknown/unavailable.
|
||||
*/
|
||||
std::chrono::system_clock::time_point mtime =
|
||||
std::chrono::system_clock::time_point::min();
|
||||
|
||||
class CompareName {
|
||||
const char *const name;
|
||||
|
@ -53,7 +57,8 @@ struct PlaylistInfo {
|
|||
PlaylistInfo() = default;
|
||||
|
||||
template<typename N>
|
||||
PlaylistInfo(N &&_name, time_t _mtime)
|
||||
explicit PlaylistInfo(N &&_name,
|
||||
std::chrono::system_clock::time_point _mtime=std::chrono::system_clock::time_point::min())
|
||||
:name(std::forward<N>(_name)), mtime(_mtime) {}
|
||||
|
||||
PlaylistInfo(const PlaylistInfo &other) = delete;
|
||||
|
|
|
@ -603,8 +603,12 @@ Visit(const struct mpd_playlist *playlist,
|
|||
if (!visit_playlist)
|
||||
return;
|
||||
|
||||
time_t mtime = mpd_playlist_get_last_modified(playlist);
|
||||
|
||||
PlaylistInfo p(mpd_playlist_get_path(playlist),
|
||||
mpd_playlist_get_last_modified(playlist));
|
||||
mtime > 0
|
||||
? std::chrono::system_clock::from_time_t(mtime)
|
||||
: std::chrono::system_clock::time_point::min());
|
||||
|
||||
visit_playlist(p, LightDirectory::Root());
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ UpdateWalk::UpdatePlaylistFile(Directory &directory,
|
|||
if (!playlist_suffix_supported(suffix))
|
||||
return false;
|
||||
|
||||
PlaylistInfo pi(name, std::chrono::system_clock::to_time_t(info.mtime));
|
||||
PlaylistInfo pi(name, info.mtime);
|
||||
|
||||
const ScopeDatabaseLock protect;
|
||||
if (directory.playlists.UpdateOrInsert(std::move(pi)))
|
||||
|
|
Loading…
Reference in New Issue