summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
authorDan Moseley <danmose@microsoft.com>2018-01-16 16:35:25 -0800
committerJan Kotas <jkotas@microsoft.com>2018-01-16 16:35:25 -0800
commitdd651509b9082f3117000e168007d5e1e1e72d32 (patch)
tree9222ca900aba47169f7876060c9b055bf2f7dd14 /src/pal
parentccc9329994b0029c91cfd7fd1aa35ccafa980f24 (diff)
downloadcoreclr-dd651509b9082f3117000e168007d5e1e1e72d32.tar.gz
coreclr-dd651509b9082f3117000e168007d5e1e1e72d32.tar.bz2
coreclr-dd651509b9082f3117000e168007d5e1e1e72d32.zip
Update filetimes to nsec (#15872)
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/src/config.h.in1
-rw-r--r--src/pal/src/configure.cmake1
-rw-r--r--src/pal/src/file/file.cpp32
-rw-r--r--src/pal/src/file/filetime.cpp6
-rw-r--r--src/pal/src/file/find.cpp18
-rw-r--r--src/pal/src/include/pal/filetime.h9
6 files changed, 59 insertions, 8 deletions
diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in
index 7968192ee3..0ff6687a8c 100644
--- a/src/pal/src/config.h.in
+++ b/src/pal/src/config.h.in
@@ -71,6 +71,7 @@
#cmakedefine01 HAVE_PR_SET_PTRACER
#cmakedefine01 HAVE_STAT_TIMESPEC
+#cmakedefine01 HAVE_STAT_TIM
#cmakedefine01 HAVE_STAT_NSEC
#cmakedefine01 HAVE_TM_GMTOFF
diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake
index d1c7506375..0f105eee94 100644
--- a/src/pal/src/configure.cmake
+++ b/src/pal/src/configure.cmake
@@ -134,6 +134,7 @@ int main(int argc, char **argv) {
}" HAVE_CPUSET_T)
check_struct_has_member ("struct stat" st_atimespec "sys/types.h;sys/stat.h" HAVE_STAT_TIMESPEC)
+check_struct_has_member ("struct stat" st_atim "sys/types.h;sys/stat.h" HAVE_STAT_TIM)
check_struct_has_member ("struct stat" st_atimensec "sys/types.h;sys/stat.h" HAVE_STAT_NSEC)
check_struct_has_member ("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
check_struct_has_member ("ucontext_t" uc_mcontext.gregs[0] ucontext.h HAVE_GREGSET_T)
diff --git a/src/pal/src/file/file.cpp b/src/pal/src/file/file.cpp
index 5db7d10ac5..be6b3426f3 100644
--- a/src/pal/src/file/file.cpp
+++ b/src/pal/src/file/file.cpp
@@ -1759,6 +1759,22 @@ GetFileAttributesExW(
FILEUnixTimeToFileTime( stat_data.st_mtime,
ST_MTIME_NSEC(&stat_data) );
+ /* if Unix mtime is greater than atime, return mtime
+ as the last access time */
+ if (CompareFileTime(&attr_data->ftLastAccessTime,
+ &attr_data->ftLastWriteTime) < 0)
+ {
+ attr_data->ftLastAccessTime = attr_data->ftLastWriteTime;
+ }
+
+ /* if Unix ctime is greater than mtime, return mtime
+ as the create time */
+ if (CompareFileTime(&attr_data->ftLastWriteTime,
+ &attr_data->ftCreationTime) < 0)
+ {
+ attr_data->ftCreationTime = attr_data->ftLastWriteTime;
+ }
+
/* Get the file size. GetFileSize is not used because it gets the
size of an already-open file */
attr_data->nFileSizeLow = (DWORD) stat_data.st_size;
@@ -4451,6 +4467,22 @@ GetFileInformationByHandle(
FILEUnixTimeToFileTime( stat_data.st_mtime,
ST_MTIME_NSEC(&stat_data) );
+ /* if Unix mtime is greater than atime, return mtime
+ as the last access time */
+ if (CompareFileTime(&lpFileInformation->ftLastAccessTime,
+ &lpFileInformation->ftLastWriteTime) < 0)
+ {
+ lpFileInformation->ftLastAccessTime = lpFileInformation->ftLastWriteTime;
+ }
+
+ /* if Unix ctime is greater than mtime, return mtime
+ as the create time */
+ if (CompareFileTime(&lpFileInformation->ftLastWriteTime,
+ &lpFileInformation->ftCreationTime) < 0)
+ {
+ lpFileInformation->ftCreationTime = lpFileInformation->ftLastWriteTime;
+ }
+
lpFileInformation->dwVolumeSerialNumber = stat_data.st_dev;
/* Get the file size. GetFileSize is not used because it gets the
diff --git a/src/pal/src/file/filetime.cpp b/src/pal/src/file/filetime.cpp
index 6cc8dacc72..bc746869b8 100644
--- a/src/pal/src/file/filetime.cpp
+++ b/src/pal/src/file/filetime.cpp
@@ -42,11 +42,11 @@ if it exists, and are defined as 0 otherwise.
--
-Also note that there is no analog to "creation time" on Unix systems.
+Also note that there is no analog to "creation time" on Linux systems.
Instead, we use the inode change time, which is set to the current time
whenever mtime changes or when chmod, chown, etc. syscalls modify the
-file status.
-
+file status; or mtime if older. Ideally we would use birthtime when
+available.
--*/
diff --git a/src/pal/src/file/find.cpp b/src/pal/src/file/find.cpp
index 18bf8c4cf1..efc651226a 100644
--- a/src/pal/src/file/find.cpp
+++ b/src/pal/src/file/find.cpp
@@ -417,24 +417,32 @@ FindNextFileA(
if ( stat_result )
{
- lpFindFileData->ftCreationTime =
+ lpFindFileData->ftCreationTime =
FILEUnixTimeToFileTime( stat_data.st_ctime,
ST_CTIME_NSEC(&stat_data) );
- lpFindFileData->ftLastAccessTime =
+ lpFindFileData->ftLastAccessTime =
FILEUnixTimeToFileTime( stat_data.st_atime,
ST_ATIME_NSEC(&stat_data) );
- lpFindFileData->ftLastWriteTime =
+ lpFindFileData->ftLastWriteTime =
FILEUnixTimeToFileTime( stat_data.st_mtime,
ST_MTIME_NSEC(&stat_data) );
- /* if Unix mtime is greater than atime, return mtime
+ /* if Unix mtime is greater than atime, return mtime
as the last access time */
- if (CompareFileTime(&lpFindFileData->ftLastAccessTime,
+ if (CompareFileTime(&lpFindFileData->ftLastAccessTime,
&lpFindFileData->ftLastWriteTime) < 0)
{
lpFindFileData->ftLastAccessTime = lpFindFileData->ftLastWriteTime;
}
+ /* if Unix ctime is greater than mtime, return mtime
+ as the create time */
+ if (CompareFileTime(&lpFindFileData->ftLastWriteTime,
+ &lpFindFileData->ftCreationTime) < 0)
+ {
+ lpFindFileData->ftCreationTime = lpFindFileData->ftLastWriteTime;
+ }
+
/* get file size */
lpFindFileData->nFileSizeLow = (DWORD)stat_data.st_size;
#if SIZEOF_OFF_T > 4
diff --git a/src/pal/src/include/pal/filetime.h b/src/pal/src/include/pal/filetime.h
index cb37b4115a..29b53a85fc 100644
--- a/src/pal/src/include/pal/filetime.h
+++ b/src/pal/src/include/pal/filetime.h
@@ -38,6 +38,14 @@ extern "C"
#else /* HAVE_STAT_TIMESPEC */
+#if HAVE_STAT_TIM
+
+#define ST_ATIME_NSEC(statstruct) ((statstruct)->st_atim.tv_nsec)
+#define ST_MTIME_NSEC(statstruct) ((statstruct)->st_mtim.tv_nsec)
+#define ST_CTIME_NSEC(statstruct) ((statstruct)->st_ctim.tv_nsec)
+
+#else /* HAVE_STAT_TIM */
+
#if HAVE_STAT_NSEC
#define ST_ATIME_NSEC(statstruct) ((statstruct)->st_atimensec)
@@ -51,6 +59,7 @@ extern "C"
#define ST_CTIME_NSEC(statstruct) 0
#endif /* HAVE_STAT_NSEC */
+#endif /* HAVE_STAT_TIM */
#endif /* HAVE_STAT_TIMESPEC */
FILETIME FILEUnixTimeToFileTime( time_t sec, long nsec );