Commit 329c3ab2 authored by Max Kellermann's avatar Max Kellermann

fs/FileInfo: use std::chrono::system_clock

parent 3b7f6641
...@@ -148,7 +148,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info, ...@@ -148,7 +148,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
return false; return false;
info.name = std::move(name_utf8); info.name = std::move(name_utf8);
info.mtime = fi.GetModificationTime(); info.mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
return true; return true;
} }
......
...@@ -151,7 +151,7 @@ DetachedSong::LoadFile(Path path) ...@@ -151,7 +151,7 @@ DetachedSong::LoadFile(Path path)
if (!tag_file_scan(path, tag_builder)) if (!tag_file_scan(path, tag_builder))
return false; return false;
mtime = fi.GetModificationTime(); mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
tag_builder.Commit(tag); tag_builder.Commit(tag);
return true; return true;
} }
......
...@@ -157,7 +157,7 @@ SimpleDatabase::Load() ...@@ -157,7 +157,7 @@ SimpleDatabase::Load()
FileInfo fi; FileInfo fi;
if (GetFileInfo(path, fi)) if (GetFileInfo(path, fi))
mtime = fi.GetModificationTime(); mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
} }
void void
...@@ -358,7 +358,7 @@ SimpleDatabase::Save() ...@@ -358,7 +358,7 @@ SimpleDatabase::Save()
FileInfo fi; FileInfo fi;
if (GetFileInfo(path, fi)) if (GetFileInfo(path, fi))
mtime = fi.GetModificationTime(); mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
} }
void void
......
...@@ -24,14 +24,16 @@ ...@@ -24,14 +24,16 @@
#include "Path.hxx" #include "Path.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include <stdint.h>
#ifdef WIN32 #ifdef WIN32
#include <fileapi.h> #include <fileapi.h>
#else #else
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#include <chrono>
#include <stdint.h>
#ifdef WIN32 #ifdef WIN32
static inline constexpr uint64_t static inline constexpr uint64_t
...@@ -47,6 +49,13 @@ FileTimeToTimeT(FILETIME ft) ...@@ -47,6 +49,13 @@ FileTimeToTimeT(FILETIME ft)
- 116444736000000000) / 10000000; - 116444736000000000) / 10000000;
} }
static std::chrono::system_clock::time_point
FileTimeToChrono(FILETIME ft)
{
// TODO: eliminate the time_t roundtrip, preserve sub-second resolution
return std::chrono::system_clock::from_time_t(FileTimeToTimeT(ft));
}
#endif #endif
class FileInfo { class FileInfo {
...@@ -100,11 +109,11 @@ public: ...@@ -100,11 +109,11 @@ public:
#endif #endif
} }
time_t GetModificationTime() const { std::chrono::system_clock::time_point GetModificationTime() const {
#ifdef WIN32 #ifdef WIN32
return FileTimeToTimeT(data.ftLastWriteTime); return FileTimeToChrono(data.ftLastWriteTime);
#else #else
return st.st_mtime; return std::chrono::system_clock::from_time_t(st.st_mtime);
#endif #endif
} }
......
...@@ -86,7 +86,7 @@ Stat(Path path, bool follow) ...@@ -86,7 +86,7 @@ Stat(Path path, bool follow)
info.type = StorageFileInfo::Type::OTHER; info.type = StorageFileInfo::Type::OTHER;
info.size = src.GetSize(); info.size = src.GetSize();
info.mtime = src.GetModificationTime(); info.mtime = std::chrono::system_clock::to_time_t(src.GetModificationTime());
#ifdef WIN32 #ifdef WIN32
info.device = info.inode = 0; info.device = info.inode = 0;
#else #else
......
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