Add lastAccessedTime to file_status

Reviewers: silvas

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D18456

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264387 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mehdi Amini 2016-03-25 05:58:11 +00:00
parent 256567583d
commit b474b03196
3 changed files with 64 additions and 33 deletions

View File

@ -140,11 +140,14 @@ class file_status
#if defined(LLVM_ON_UNIX)
dev_t fs_st_dev;
ino_t fs_st_ino;
time_t fs_st_atime;
time_t fs_st_mtime;
uid_t fs_st_uid;
gid_t fs_st_gid;
off_t fs_st_size;
#elif defined (LLVM_ON_WIN32)
uint32_t LastAccessedTimeHigh;
uint32_t LastAccessedTimeLow;
uint32_t LastWriteTimeHigh;
uint32_t LastWriteTimeLow;
uint32_t VolumeSerialNumber;
@ -159,34 +162,40 @@ class file_status
public:
#if defined(LLVM_ON_UNIX)
file_status() : fs_st_dev(0), fs_st_ino(0), fs_st_mtime(0),
file_status()
: fs_st_dev(0), fs_st_ino(0), fs_st_atime(0), fs_st_mtime(0),
fs_st_uid(0), fs_st_gid(0), fs_st_size(0),
Type(file_type::status_error), Perms(perms_not_known) {}
file_status(file_type Type) : fs_st_dev(0), fs_st_ino(0), fs_st_mtime(0),
file_status(file_type Type)
: fs_st_dev(0), fs_st_ino(0), fs_st_atime(0), fs_st_mtime(0),
fs_st_uid(0), fs_st_gid(0), fs_st_size(0), Type(Type),
Perms(perms_not_known) {}
file_status(file_type Type, perms Perms, dev_t Dev, ino_t Ino, time_t MTime,
uid_t UID, gid_t GID, off_t Size)
: fs_st_dev(Dev), fs_st_ino(Ino), fs_st_mtime(MTime), fs_st_uid(UID),
fs_st_gid(GID), fs_st_size(Size), Type(Type), Perms(Perms) {}
time_t ATime, uid_t UID, gid_t GID, off_t Size)
: fs_st_dev(Dev), fs_st_ino(Ino), fs_st_atime(ATime), fs_st_mtime(MTime),
fs_st_uid(UID), fs_st_gid(GID), fs_st_size(Size), Type(Type),
Perms(Perms) {}
#elif defined(LLVM_ON_WIN32)
file_status() : LastWriteTimeHigh(0), LastWriteTimeLow(0),
VolumeSerialNumber(0), FileSizeHigh(0), FileSizeLow(0),
FileIndexHigh(0), FileIndexLow(0), Type(file_type::status_error),
Perms(perms_not_known) {}
file_status()
: LastAccessedTimeHigh(0), LastAccessedTimeLow(0), LastWriteTimeHigh(0),
LastWriteTimeLow(0), VolumeSerialNumber(0), FileSizeHigh(0),
FileSizeLow(0), FileIndexHigh(0), FileIndexLow(0),
Type(file_type::status_error), Perms(perms_not_known) {}
file_status(file_type Type) : LastWriteTimeHigh(0), LastWriteTimeLow(0),
VolumeSerialNumber(0), FileSizeHigh(0), FileSizeLow(0),
FileIndexHigh(0), FileIndexLow(0), Type(Type),
file_status(file_type Type)
: LastAccessedTimeHigh(0), LastAccessedTimeLow(0), LastWriteTimeHigh(0),
LastWriteTimeLow(0), VolumeSerialNumber(0), FileSizeHigh(0),
FileSizeLow(0), FileIndexHigh(0), FileIndexLow(0), Type(Type),
Perms(perms_not_known) {}
file_status(file_type Type, uint32_t LastWriteTimeHigh,
uint32_t LastWriteTimeLow, uint32_t VolumeSerialNumber,
uint32_t FileSizeHigh, uint32_t FileSizeLow,
uint32_t FileIndexHigh, uint32_t FileIndexLow)
: LastWriteTimeHigh(LastWriteTimeHigh),
: LastAccessedTimeHigh(0), LastAccessedTimeLow(0),
LastWriteTimeHigh(LastWriteTimeHigh),
LastWriteTimeLow(LastWriteTimeLow),
VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh),
FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh),
@ -196,6 +205,7 @@ public:
// getters
file_type type() const { return Type; }
perms permissions() const { return Perms; }
TimeValue getLastAccessedTime() const;
TimeValue getLastModificationTime() const;
UniqueID getUniqueID() const;

View File

@ -174,6 +174,12 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
return "";
}
TimeValue file_status::getLastAccessedTime() const {
TimeValue Ret;
Ret.fromEpochTime(fs_st_atime);
return Ret;
}
TimeValue file_status::getLastModificationTime() const {
TimeValue Ret;
Ret.fromEpochTime(fs_st_mtime);
@ -373,8 +379,9 @@ static std::error_code fillStatus(int StatRet, const struct stat &Status,
perms Perms = static_cast<perms>(Status.st_mode);
Result =
file_status(Type, Perms, Status.st_dev, Status.st_ino, Status.st_mtime,
Status.st_uid, Status.st_gid, Status.st_size);
file_status(Type, Perms, Status.st_dev, Status.st_ino, Status.st_atime,
Status.st_mtime, Status.st_uid, Status.st_gid,
Status.st_size);
return std::error_code();
}

View File

@ -151,6 +151,16 @@ UniqueID file_status::getUniqueID() const {
return UniqueID(VolumeSerialNumber, FileID);
}
TimeValue file_status::getLastAccessedTime() const {
ULARGE_INTEGER UI;
UI.LowPart = LastAccessedTimeLow;
UI.HighPart = LastAccessedTimeHigh;
TimeValue Ret;
Ret.fromWin32Time(UI.QuadPart);
return Ret;
}
TimeValue file_status::getLastModificationTime() const {
ULARGE_INTEGER UI;
UI.LowPart = LastWriteTimeLow;
@ -331,6 +341,8 @@ bool equivalent(file_status A, file_status B) {
A.FileIndexLow == B.FileIndexLow &&
A.FileSizeHigh == B.FileSizeHigh &&
A.FileSizeLow == B.FileSizeLow &&
A.LastAccessedTimeHigh == B.LastAccessedTimeHigh &&
A.LastAccessedTimeLow == B.LastAccessedTimeLow &&
A.LastWriteTimeHigh == B.LastWriteTimeHigh &&
A.LastWriteTimeLow == B.LastWriteTimeLow &&
A.VolumeSerialNumber == B.VolumeSerialNumber;
@ -404,7 +416,9 @@ static std::error_code getStatus(HANDLE FileHandle, file_status &Result) {
? file_type::directory_file
: file_type::regular_file;
Result =
file_status(Type, Info.ftLastWriteTime.dwHighDateTime,
file_status(Type, Info.lpLastAccessTime.dwHighDateTime,
Info.lpLastAccessTime.dwLowDateTime,
Info.ftLastWriteTime.dwHighDateTime,
Info.ftLastWriteTime.dwLowDateTime,
Info.dwVolumeSerialNumber, Info.nFileSizeHigh,
Info.nFileSizeLow, Info.nFileIndexHigh, Info.nFileIndexLow);