Skip to content

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

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.

conststd=@import("std");
pubfnmain() !void {
returnstd.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

varrc=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=>returnerror.FileNotFound,
.INVALID_PARAMETER=>unreachable,
.FILE_IS_A_DIRECTORY=>returnerror.IsDir,
else=>returnw.unexpectedStatus(rc),
}

Metadata

Metadata

Assignees

No one assigned

    Labels

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