From de9abe1f7b6bb31fa1166393368f9ce51aadd01a Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Fri, 2 Aug 2024 21:55:45 +0200 Subject: [PATCH] os2: skip . and .. in read dir --- core/os/os2/dir_posix.odin | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/core/os/os2/dir_posix.odin b/core/os/os2/dir_posix.odin index 4bf2156f2..6e01928e0 100644 --- a/core/os/os2/dir_posix.odin +++ b/core/os/os2/dir_posix.odin @@ -17,36 +17,36 @@ _read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info index = it.impl.idx it.impl.idx += 1 - entry := posix.readdir(it.impl.dir) - if entry == nil { - // NOTE(laytan): would be good to have an `error` field on the `Read_Directory_Iterator` - // There isn't a way to now know if it failed or if we are at the end. + for { + entry := posix.readdir(it.impl.dir) + if entry == nil { + // NOTE(laytan): would be good to have an `error` field on the `Read_Directory_Iterator` + // There isn't a way to now know if it failed or if we are at the end. + return + } + + cname := cstring(raw_data(entry.d_name[:])) + if cname == "." || cname == ".." { + continue + } + + stat: posix.stat_t + if posix.fstatat(posix.dirfd(it.impl.dir), cname, &stat, { .SYMLINK_NOFOLLOW }) != .OK { + // NOTE(laytan): would be good to have an `error` field on the `Read_Directory_Iterator` + // There isn't a way to now know if it failed or if we are at the end. + return + } + + fimpl := (^File_Impl)(it.f.impl) + + n := copy(it.impl.fullpath[:], fimpl.name) + n += copy(it.impl.fullpath[n:], "/") + n += copy(it.impl.fullpath[n:], string(cname)) + + fi = internal_stat(stat, string(it.impl.fullpath[:n])) + ok = true return } - - cname := cstring(raw_data(entry.d_name[:])) - - // NOTE: these shouldn't be given back, but how? - // if cname == "." || cname == ".." { - // continue - // } - - stat: posix.stat_t - if posix.fstatat(posix.dirfd(it.impl.dir), cname, &stat, { .SYMLINK_NOFOLLOW }) != .OK { - // NOTE(laytan): would be good to have an `error` field on the `Read_Directory_Iterator` - // There isn't a way to now know if it failed or if we are at the end. - return - } - - fimpl := (^File_Impl)(it.f.impl) - - n := copy(it.impl.fullpath[:], fimpl.name) - n += copy(it.impl.fullpath[n:], "/") - n += copy(it.impl.fullpath[n:], string(cname)) - - fi = internal_stat(stat, string(it.impl.fullpath[:n])) - ok = true - return } @(require_results)