const configDir = std.fs.openDirAbsolute(configDirPath, .{ .iterate = true }) catch |err| cd: {
if (err == error.FileNotFound) {
//If Directory not found create it.
const prompt = try std.fmt.allocPrint(allocator, "Can't find dir {s} Want me to create it?(y/N) ", .{configDirPath});
defer allocator.free(prompt);
_ = switch (choice(prompt)) {
'y' => {},
'Y' => {},
else => return error.FileNotFound,
};
try std.fs.makeDirAbsolute(configDirPath);
break :cd try std.fs.openDirAbsolute(configDirPath, .{});
} else {
return err;
}
};
....
var cdIter = configDir.iterate();
//Failure
while (try cdIter.next()) |entry| {
// std.log.debug("Iterating through entry => {s} of kind => {any}", .{ entry.name, entry.kind });
if (entry.kind == .file) {
const entryInfo = try configDir.statFile(entry.name);
try dirListing.append(File{ .name = entry.name, .lastMod = entryInfo.mtime, .path = "default" });
}
}
I'm trying to iterate through a Dir and getting to unreachable code in std lib.
thread 159665 panic: reached unreachable code
/snap/zig/11625/lib/std/posix.zig:5082:18: 0x10782a8 in lseek_SET (dotman)
.BADF => unreachable, // always a race condition
^
/snap/zig/11625/lib/std/fs/Dir.zig:359:40: 0x10440a4 in nextLinux (dotman)
posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
^
/snap/zig/11625/lib/std/fs/Dir.zig:343:34: 0x103d197 in next (dotman)
return self.nextLinux() catch |err| switch (err) {
^
/home/evil/work/proj/dotman/src/main.zig:59:27: 0x103bd4d in main (dotman)
while (try cdIter.next()) |entry| {