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

This commit is contained in:
Max Kellermann 2017-02-10 23:44:51 +01:00
parent 3b7f6641d2
commit 329c3ab21b
5 changed files with 19 additions and 10 deletions

View File

@ -148,7 +148,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
return false;
info.name = std::move(name_utf8);
info.mtime = fi.GetModificationTime();
info.mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
return true;
}

View File

@ -151,7 +151,7 @@ DetachedSong::LoadFile(Path path)
if (!tag_file_scan(path, tag_builder))
return false;
mtime = fi.GetModificationTime();
mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
tag_builder.Commit(tag);
return true;
}

View File

@ -157,7 +157,7 @@ SimpleDatabase::Load()
FileInfo fi;
if (GetFileInfo(path, fi))
mtime = fi.GetModificationTime();
mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
}
void
@ -358,7 +358,7 @@ SimpleDatabase::Save()
FileInfo fi;
if (GetFileInfo(path, fi))
mtime = fi.GetModificationTime();
mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
}
void

View File

@ -24,14 +24,16 @@
#include "Path.hxx"
#include "system/Error.hxx"
#include <stdint.h>
#ifdef WIN32
#include <fileapi.h>
#else
#include <sys/stat.h>
#endif
#include <chrono>
#include <stdint.h>
#ifdef WIN32
static inline constexpr uint64_t
@ -47,6 +49,13 @@ FileTimeToTimeT(FILETIME ft)
- 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
class FileInfo {
@ -100,11 +109,11 @@ public:
#endif
}
time_t GetModificationTime() const {
std::chrono::system_clock::time_point GetModificationTime() const {
#ifdef WIN32
return FileTimeToTimeT(data.ftLastWriteTime);
return FileTimeToChrono(data.ftLastWriteTime);
#else
return st.st_mtime;
return std::chrono::system_clock::from_time_t(st.st_mtime);
#endif
}

View File

@ -86,7 +86,7 @@ Stat(Path path, bool follow)
info.type = StorageFileInfo::Type::OTHER;
info.size = src.GetSize();
info.mtime = src.GetModificationTime();
info.mtime = std::chrono::system_clock::to_time_t(src.GetModificationTime());
#ifdef WIN32
info.device = info.inode = 0;
#else