From 59912a7f21bcb417472cf0ba63119c28f89a8fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 18 Jan 2021 10:42:21 +0100 Subject: [PATCH] Fix compilation of the directory iteration code on additional POSIX based platforms. --- source/vibe/core/file.d | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index a69b861..a403d19 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -1042,6 +1042,25 @@ private void performListDirectory(ListDirectoryRequest req) fi.directory = path; fi.hidden = de.d_name[0] == '.'; + static SysTime getTimeField(string f)(ref const stat_t st) + { + long secs, nsecs; + static if (is(typeof(__traits(getMember, st, f)))) { + secs = __traits(getMember, st, f).tv_sec; + nsecs = __traits(getMember, st, f).tv_nsec; + } else { + secs = __traits(getMember, st, f ~ "e"); + static if (is(typeof(__traits(getMember, st, f ~ "ensec")))) + nsecs = __traits(getMember, st, f ~ "ensec"); + else static if (is(typeof(__traits(getMember, st, "__" ~ f ~ "ensec")))) + nsecs = __traits(getMember, st, "__" ~ f ~ "ensec"); + else static if (is(typeof(__traits(getMember, st, "__" ~ f ~ "e_nsec")))) + nsecs = __traits(getMember, st, "__" ~ f ~ "e_nsec"); + else static assert(false, "Found no nanoseconds fields in struct stat"); + } + return timebase + secs.seconds + (nsecs / 100).hnsecs; + } + stat_t st; if (fstatat(dfd, fi.name.toStringz, &st, AT_SYMLINK_NOFOLLOW) == 0) { fi.isSymlink = S_ISLNK(st.st_mode); @@ -1050,8 +1069,8 @@ private void performListDirectory(ListDirectoryRequest req) if (fi.isSymlink) fstatat(dfd, fi.name.toStringz, &st, 0); fi.size = st.st_size; - fi.timeModified = timebase + st.st_mtime.seconds + (st.st_mtimensec / 100).hnsecs; - fi.timeCreated = timebase + st.st_ctime.seconds + (st.st_ctimensec / 100).hnsecs; + fi.timeModified = getTimeField!"st_mtim"(st); + fi.timeCreated = getTimeField!"st_ctim"(st); fi.isDirectory = S_ISDIR(st.st_mode); fi.isFile = S_ISREG(st.st_mode); }