Skip to content

Commit

Permalink
Use either the CreationTime or ChangeTime of the FILE_BASIC_INFO.
Browse files Browse the repository at this point in the history
We switched to using the GetFileInformationByHandleEx() API call
when available to also get changes to directories when ACLs get
updated. It seems we need to take the highest value of the
CreationTime and ChangeTime value of the FILE_BASIC_INFO structure
to get a proper st_ctime stat structure field.
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 7582a15 commit 7363cfb
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/win32/compat/compat.c
Expand Up @@ -1209,7 +1209,11 @@ static int get_windows_file_info(const char *filename, struct stat *sb, bool is_

pftLastAccessTime = (FILETIME *)&binfo.LastAccessTime;
pftLastWriteTime = (FILETIME *)&binfo.LastWriteTime;
pftCreationTime = (FILETIME *)&binfo.ChangeTime;
if (cvt_ftime_to_utime(binfo.CreationTime) > cvt_ftime_to_utime(binfo.ChangeTime)) {
pftCreationTime = (FILETIME *)&binfo.CreationTime;
} else {
pftCreationTime = (FILETIME *)&binfo.ChangeTime;
}
} else {
#endif
pftLastAccessTime = &info_w.ftLastAccessTime;
Expand Down Expand Up @@ -1244,7 +1248,11 @@ static int get_windows_file_info(const char *filename, struct stat *sb, bool is_

pftLastAccessTime = (FILETIME *)&binfo.LastAccessTime;
pftLastWriteTime = (FILETIME *)&binfo.LastWriteTime;
pftCreationTime = (FILETIME *)&binfo.ChangeTime;
if (cvt_ftime_to_utime(binfo.CreationTime) > cvt_ftime_to_utime(binfo.ChangeTime)) {
pftCreationTime = (FILETIME *)&binfo.CreationTime;
} else {
pftCreationTime = (FILETIME *)&binfo.ChangeTime;
}
} else {
#endif
pftLastAccessTime = &info_a.ftLastAccessTime;
Expand Down Expand Up @@ -1438,7 +1446,11 @@ int fstat(intptr_t fd, struct stat *sb)

sb->st_atime = cvt_ftime_to_utime(binfo.LastAccessTime);
sb->st_mtime = cvt_ftime_to_utime(binfo.LastWriteTime);
sb->st_ctime = cvt_ftime_to_utime(binfo.ChangeTime);
if (cvt_ftime_to_utime(binfo.CreationTime) > cvt_ftime_to_utime(binfo.ChangeTime)) {
sb->st_ctime = cvt_ftime_to_utime(binfo.CreationTime);
} else {
sb->st_ctime = cvt_ftime_to_utime(binfo.ChangeTime);
}
} else {
#endif
sb->st_atime = cvt_ftime_to_utime(info.ftLastAccessTime);
Expand Down Expand Up @@ -1664,7 +1676,11 @@ int stat(const char *filename, struct stat *sb)

sb->st_atime = cvt_ftime_to_utime(binfo.LastAccessTime);
sb->st_mtime = cvt_ftime_to_utime(binfo.LastWriteTime);
sb->st_ctime = cvt_ftime_to_utime(binfo.ChangeTime);
if (cvt_ftime_to_utime(binfo.CreationTime) > cvt_ftime_to_utime(binfo.ChangeTime)) {
sb->st_ctime = cvt_ftime_to_utime(binfo.CreationTime);
} else {
sb->st_ctime = cvt_ftime_to_utime(binfo.ChangeTime);
}

CloseHandle(h);
} else {
Expand Down

0 comments on commit 7363cfb

Please sign in to comment.