From 4b1822ade8eda7cda798dc0d0b22e1f1d7040a8f Mon Sep 17 00:00:00 2001 From: CiD- Date: Mon, 14 Mar 2022 15:48:47 -0400 Subject: [PATCH] mkdir_all: close last open file --- core/os/os2/path_linux.odin | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/os/os2/path_linux.odin b/core/os/os2/path_linux.odin index e47bd36b0..fa47f1883 100644 --- a/core/os/os2/path_linux.odin +++ b/core/os/os2/path_linux.odin @@ -35,7 +35,7 @@ _mkdir :: proc(path: string, perm: File_Mode) -> Error { _mkdir_all :: proc(path: string, perm: File_Mode) -> Error { _mkdirat :: proc(dfd: Handle, path: []u8, perm: int, has_created: ^bool) -> Error { if len(path) == 0 { - return nil + return _ok_or_error(unix.sys_close(int(dfd))) } i: int for /**/; i < len(path) - 1 && path[i] != '/'; i += 1 {} @@ -43,18 +43,18 @@ _mkdir_all :: proc(path: string, perm: File_Mode) -> Error { new_dfd := unix.sys_openat(int(dfd), cstring(&path[0]), _OPENDIR_FLAGS) switch new_dfd { case -ENOENT: - res := unix.sys_mkdirat(int(dfd), cstring(&path[0]), perm) - if res < 0 { + if res := unix.sys_mkdirat(int(dfd), cstring(&path[0]), perm); res < 0 { return _get_platform_error(res) } has_created^ = true - new_dfd = unix.sys_openat(int(dfd), cstring(&path[0]), _OPENDIR_FLAGS) - if new_dfd < 0 { + if new_dfd = unix.sys_openat(int(dfd), cstring(&path[0]), _OPENDIR_FLAGS); new_dfd < 0 { return _get_platform_error(new_dfd) } fallthrough case 0: - unix.sys_close(int(dfd)) + if res := unix.sys_close(int(dfd)) < 0; res < 0 { + return _get_platform_error(res) + } // skip consecutive '/' for i += 1; i < len(path) && path[i] == '/'; i += 1 {} return _mkdirat(Handle(new_dfd), path[i:], perm, has_created)