Merge pull request #249 from vibe-d/fix_listdir_posix

Fix compilation of the directory iteration code on additional POSIX based platforms
This commit is contained in:
Sönke Ludwig 2021-01-18 14:38:21 +01:00 committed by GitHub
commit 397527a0a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1042,6 +1042,25 @@ private void performListDirectory(ListDirectoryRequest req)
fi.directory = path; fi.directory = path;
fi.hidden = de.d_name[0] == '.'; 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; stat_t st;
if (fstatat(dfd, fi.name.toStringz, &st, AT_SYMLINK_NOFOLLOW) == 0) { if (fstatat(dfd, fi.name.toStringz, &st, AT_SYMLINK_NOFOLLOW) == 0) {
fi.isSymlink = S_ISLNK(st.st_mode); 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); if (fi.isSymlink) fstatat(dfd, fi.name.toStringz, &st, 0);
fi.size = st.st_size; fi.size = st.st_size;
fi.timeModified = timebase + st.st_mtime.seconds + (st.st_mtimensec / 100).hnsecs; fi.timeModified = getTimeField!"st_mtim"(st);
fi.timeCreated = timebase + st.st_ctime.seconds + (st.st_ctimensec / 100).hnsecs; fi.timeCreated = getTimeField!"st_ctim"(st);
fi.isDirectory = S_ISDIR(st.st_mode); fi.isDirectory = S_ISDIR(st.st_mode);
fi.isFile = S_ISREG(st.st_mode); fi.isFile = S_ISREG(st.st_mode);
} }
@ -1103,6 +1122,11 @@ version (Posix) {
static if (!is(typeof(AT_SYMLINK_NOFOLLOW))) static if (!is(typeof(AT_SYMLINK_NOFOLLOW)))
enum AT_SYMLINK_NOFOLLOW = 0x0020; enum AT_SYMLINK_NOFOLLOW = 0x0020;
} }
version (CRuntime_Musl) {
static if (!is(typeof(AT_SYMLINK_NOFOLLOW)))
enum AT_SYMLINK_NOFOLLOW = 0x0100;
}
} }
private immutable TaskSettings ioTaskSettings = { priority: 20 * Task.basePriority }; private immutable TaskSettings ioTaskSettings = { priority: 20 * Task.basePriority };