Skip to content

std.fs: deleteTree in dir with open file hangs in loop #19233

@ianic

Description

@ianic

Zig Version

0.12.0-dev.1800+559e216f3

Steps to Reproduce and Observed Behavior

This test fails on Windows when run with -target aarch64-windows-gnu on other platforms and on Windows without target flag passes.

Created file is not closed and then in tmp.cleanup() deleteTree loops in trying to delete that file.

Closing created file makes test pass.
Removing line tmp.dir.close() also makes test pass without closing file.

test "not closing file" {
    var tmp = std.testing.tmpDir(.{});

    // This file is not closed !!!
    _ = try tmp.dir.createFile("file1", .{ .exclusive = true });

    // Next lines are from tmp.cleanup();
    tmp.dir.close();
    // This produces endless loop
    tmp.parent_dir.deleteTree(&tmp.sub_path) catch {};
    tmp.parent_dir.close();
}

Expected Behavior

deleteTree should return an error instead of trying forever to delete the same file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions