Skip to content

fs.cwd().openDir().iterate() panics if called without OpenDirOptions.iterate = true on Linux (Ubuntu), works fine on MacOS #12007

@renatoathaydes

Description

@renatoathaydes

Zig Version

0.10.0-dev.2577+5816d3eae

Steps to Reproduce

Call this:

var children = try std.fs.cwd().openDir("some-dir", .{});
defer children.close();
_ = children.iterate();

Expected Behavior

The call should return an error as the default is iterate=false.

On MacOS, no error happens at all, which is probably also a bug?

Actual Behavior

thread 1827 panic: reached unreachable code
/opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/lib/std/os.zig:4342:18: 0x2a5567 in std.os.lseek_SET (build)
        .BADF => unreachable, // always a race condition
                 ^
/opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/lib/std/fs.zig:597:45: 0x29c530 in std.fs.Iterator.next (build)
                            std.os.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
                                            ^
/home/runner/work/zig-common-tasks/zig-common-tasks/build.zig:17:34: 0x29e288 in .@build.testAllSamples (build)
    var child = try iterator.next();
                                 ^
/home/runner/work/zig-common-tasks/zig-common-tasks/build.zig:6:19: 0x2920c6 in .@build.build (build)
    testAllSamples(b, test_step) catch |e| {
                  ^
/opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/lib/std/special/build_runner.zig:220:28: 0x2838e4 in runBuild (build)
        .Void => root.build(builder),
                           ^
/opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/lib/std/special/build_runner.zig:202:17: 0x27855f in main (build)
    try runBuild(builder);
                ^
/opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/lib/std/start.zig:561:37: 0x26ff1a in std.start.callMain (build)
            const result = root.main() catch |err| {
                                    ^
/opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/lib/std/start.zig:495:12: 0x250b2e in std.start.callMainWithArgs (build)
    return @call(.{ .modifier = .always_inline }, callMain, .{});
           ^
/opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/lib/std/start.zig:409:17: 0x24fbc6 in std.start.posixCallMainAndExit (build)
    std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp }));
                ^
/opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/lib/std/start.zig:322:5: 0x24f9d2 in std.start._start (build)
    @call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{});
    ^
error: the following build command crashed:
/home/runner/work/zig-common-tasks/zig-common-tasks/zig-cache/o/68e59b58dd56ed02a9db570b274bcbd5/build /opt/hostedtoolcache/zig/zig-linux-x86_64-0.9.1/x64/zig /home/runner/work/zig-common-tasks/zig-common-tasks /home/runner/work/zig-common-tasks/zig-common-tasks/zig-cache /home/runner/.cache/zig test

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions