Skip to content

Windows: std.fs.Dir.deleteDir() will silently fail on non-empty directories #5537

@squeek502

Description

@squeek502

When ./dir is non-empty, the following code will succeed but the directory will not be deleted. I expect error.DirNotEmpty to be returned in this case.

const std = @import("std");

pub fn main() !void {
    return std.fs.cwd().deleteDir("dir");
}

Both NtCreateFile and NtClose seem to be returning SUCCESS here:

zig/lib/std/os.zig

Lines 1768 to 1791 in fd067fb

var rc = w.ntdll.NtCreateFile(
&tmp_handle,
w.SYNCHRONIZE | w.DELETE,
&attr,
&io,
null,
0,
w.FILE_SHARE_READ | w.FILE_SHARE_WRITE | w.FILE_SHARE_DELETE,
w.FILE_OPEN,
create_options_flags,
null,
0,
);
if (rc == .SUCCESS) {
rc = w.ntdll.NtClose(tmp_handle);
}
switch (rc) {
.SUCCESS => return,
.OBJECT_NAME_INVALID => unreachable,
.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
.INVALID_PARAMETER => unreachable,
.FILE_IS_A_DIRECTORY => return error.IsDir,
else => return w.unexpectedStatus(rc),
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavioros-windowsstandard 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