From ad2ff9e65d91bd04ca48a7aceee3931ab7b00652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Thu, 19 Nov 2020 13:54:29 +0000 Subject: [PATCH 1/3] darwin: getdents: entry with d_ino==0 should be skipped --- lib/std/fs.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 00eec0b823..8475b28136 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -352,7 +352,7 @@ pub const Dir = struct { const name = @ptrCast([*]u8, &darwin_entry.d_name)[0..darwin_entry.d_namlen]; - if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) { + if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (darwin_entry.d_ino == 0)) { continue :start_over; } From 7579ce180f2bf4b5da6ecca5db83af6789c2f576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Thu, 19 Nov 2020 13:54:47 +0000 Subject: [PATCH 2/3] Iterator: rename freebsd_entry to bsd_entry to reflect that nextBsd is not freebsd only --- lib/std/fs.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 8475b28136..d144906545 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -393,17 +393,17 @@ pub const Dir = struct { self.index = 0; self.end_index = @intCast(usize, rc); } - const freebsd_entry = @ptrCast(*align(1) os.dirent, &self.buf[self.index]); - const next_index = self.index + freebsd_entry.reclen(); + const bsd_entry = @ptrCast(*align(1) os.dirent, &self.buf[self.index]); + const next_index = self.index + bsd_entry.reclen(); self.index = next_index; - const name = @ptrCast([*]u8, &freebsd_entry.d_name)[0..freebsd_entry.d_namlen]; + const name = @ptrCast([*]u8, &bsd_entry.d_name)[0..bsd_entry.d_namlen]; if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) { continue :start_over; } - const entry_kind = switch (freebsd_entry.d_type) { + const entry_kind = switch (bsd_entry.d_type) { os.DT_BLK => Entry.Kind.BlockDevice, os.DT_CHR => Entry.Kind.CharacterDevice, os.DT_DIR => Entry.Kind.Directory, From b174942e6a7e15bf78edc3098fcbcdf1b2fbccd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Thu, 19 Nov 2020 13:55:46 +0000 Subject: [PATCH 3/3] openbsd, netbsd: getdents: entry with d_fileno==0 should be skipped --- lib/std/fs.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index d144906545..db95b2a7d1 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -399,7 +399,14 @@ pub const Dir = struct { const name = @ptrCast([*]u8, &bsd_entry.d_name)[0..bsd_entry.d_namlen]; - if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) { + const skip_zero_fileno = switch (builtin.os.tag) { + // d_fileno=0 is used to mark invalid entries or deleted files. + .openbsd, .netbsd => true, + else => false, + }; + if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or + (skip_zero_fileno and bsd_entry.d_fileno == 0)) + { continue :start_over; }