storage/FileInfo: convert mtime to std::chrono::system_clock::time_point
This commit is contained in:
@@ -22,7 +22,8 @@
|
||||
|
||||
#include "check.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <chrono>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct StorageFileInfo {
|
||||
@@ -40,9 +41,10 @@ struct StorageFileInfo {
|
||||
uint64_t size;
|
||||
|
||||
/**
|
||||
* The modification time. 0 means unknown / not applicable.
|
||||
* The modification time. A negative value means unknown /
|
||||
* not applicable.
|
||||
*/
|
||||
time_t mtime;
|
||||
std::chrono::system_clock::time_point mtime;
|
||||
|
||||
/**
|
||||
* Device id and inode number. 0 means unknown / not
|
||||
@@ -55,7 +57,7 @@ struct StorageFileInfo {
|
||||
explicit constexpr StorageFileInfo(Type _type)
|
||||
:type(_type),
|
||||
size(0),
|
||||
mtime(0),
|
||||
mtime(std::chrono::system_clock::time_point::min()),
|
||||
device(0), inode(0) {}
|
||||
|
||||
constexpr bool IsRegular() const {
|
||||
|
@@ -418,9 +418,7 @@ protected:
|
||||
? StorageFileInfo::Type::DIRECTORY
|
||||
: StorageFileInfo::Type::REGULAR;
|
||||
info.size = r.length;
|
||||
info.mtime = !IsNegative(r.mtime)
|
||||
? std::chrono::system_clock::to_time_t(r.mtime)
|
||||
: 0;
|
||||
info.mtime = r.mtime;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -514,9 +512,7 @@ protected:
|
||||
? StorageFileInfo::Type::DIRECTORY
|
||||
: StorageFileInfo::Type::REGULAR);
|
||||
info.size = r.length;
|
||||
info.mtime = !IsNegative(r.mtime)
|
||||
? std::chrono::system_clock::to_time_t(r.mtime)
|
||||
: 0;
|
||||
info.mtime = r.mtime;
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -86,7 +86,7 @@ Stat(Path path, bool follow)
|
||||
info.type = StorageFileInfo::Type::OTHER;
|
||||
|
||||
info.size = src.GetSize();
|
||||
info.mtime = std::chrono::system_clock::to_time_t(src.GetModificationTime());
|
||||
info.mtime = src.GetModificationTime();
|
||||
#ifdef WIN32
|
||||
info.device = info.inode = 0;
|
||||
#else
|
||||
|
@@ -250,7 +250,7 @@ Copy(StorageFileInfo &info, const struct stat &st)
|
||||
info.type = StorageFileInfo::Type::OTHER;
|
||||
|
||||
info.size = st.st_size;
|
||||
info.mtime = st.st_mtime;
|
||||
info.mtime = std::chrono::system_clock::from_time_t(st.st_mtime);
|
||||
info.device = st.st_dev;
|
||||
info.inode = st.st_ino;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ Copy(StorageFileInfo &info, const struct nfsdirent &ent)
|
||||
}
|
||||
|
||||
info.size = ent.size;
|
||||
info.mtime = ent.mtime.tv_sec;
|
||||
info.mtime = std::chrono::system_clock::from_time_t(ent.mtime.tv_sec);
|
||||
info.device = 0;
|
||||
info.inode = ent.inode;
|
||||
}
|
||||
|
@@ -111,7 +111,7 @@ GetInfo(const char *path)
|
||||
info.type = StorageFileInfo::Type::OTHER;
|
||||
|
||||
info.size = st.st_size;
|
||||
info.mtime = st.st_mtime;
|
||||
info.mtime = std::chrono::system_clock::from_time_t(st.st_mtime);
|
||||
info.device = st.st_dev;
|
||||
info.inode = st.st_ino;
|
||||
return info;
|
||||
|
Reference in New Issue
Block a user