From dda72bd0bc9d7ab22028d42092820837153eb021 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Mon, 11 Sep 2023 13:54:02 -0700 Subject: [PATCH] sys.FileStat.ctime updated with more accurate file creation time Linux: Uses statx syscall on Linux to get stx_btime.tv_sec for this field only macOS: Still uses the existing stat syscall, but accesses the macOS-only st_birthtime field instead Historically, the POSIX standard did not require file systems to store the file creation time at all, so the stat syscall did not provide it. Modern file systems now store this value, and different operating systems provide it in different ways. The previous value of ctime from the stat syscall is actually the "status change time". This value may initially match the file creation time, but it can be updated after the file is modified in certain ways (including the file size changing, which is very common). The new value is more accurate, better matching how Haxe documents this field. --- src/hx/libs/std/Sys.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/hx/libs/std/Sys.cpp b/src/hx/libs/std/Sys.cpp index 30ad2e29c..e51b7d47e 100644 --- a/src/hx/libs/std/Sys.cpp +++ b/src/hx/libs/std/Sys.cpp @@ -19,6 +19,7 @@ #include #include #else + #include #include #ifndef EPPC #include @@ -454,6 +455,16 @@ Dynamic _hx_std_sys_stat( String path ) hx::strbuf buf; err = _stat(path.utf8_str(&buf),&s); } + #elif defined(HX_LINUX) + struct stat s; + hx::strbuf buf; + err = stat(path.utf8_str(&buf),&s); + struct statx sx; + if (!err) + { + hx::strbuf buf2; + err = statx(AT_FDCWD,path.utf8_str(&buf2),0,STATX_BTIME,&sx); + } #else struct stat s; hx::strbuf buf; @@ -469,7 +480,13 @@ Dynamic _hx_std_sys_stat( String path ) STATF(uid); STATF(atime); STATF(mtime); + #if defined(HX_LINUX) + o->Add(HX_CSTRING("ctime"),(int)(sx.stx_btime.tv_sec)); + #elif defined(HX_MACOS) + o->Add(HX_CSTRING("ctime"),(int)(s.st_birthtime)); + #else STATF(ctime); + #endif STATF(dev); STATF(ino); STATF(mode);