From 76a00bf9c392a774f75e7b3c94b578b923f0e9c5 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 11 Dec 2023 12:21:47 -0600 Subject: [PATCH] fixed: inability to remove read-only files on Windows --- runtime/src/ort_files.h | 6 ++++++ scripts/onyx-pkg.onyx | 4 ++-- shared/include/small_windows.h | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/runtime/src/ort_files.h b/runtime/src/ort_files.h index 148454e6..87ec350f 100644 --- a/runtime/src/ort_files.h +++ b/runtime/src/ort_files.h @@ -89,6 +89,12 @@ ONYX_DEF(__file_remove, (WASM_I32, WASM_I32), (WASM_I32)) { strncpy(path, path_ptr, path_len); path[path_len] = 0; + #if _BH_WINDOWS + DWORD attrs = GetFileAttributesA(path); + attrs &= ~FILE_ATTRIBUTE_READONLY; + SetFileAttributesA(path, attrs); + #endif + results->data[0] = WASM_I32_VAL(bh_file_remove(path)); return NULL; } diff --git a/scripts/onyx-pkg.onyx b/scripts/onyx-pkg.onyx index 0159a926..508fc183 100644 --- a/scripts/onyx-pkg.onyx +++ b/scripts/onyx-pkg.onyx @@ -1047,10 +1047,10 @@ Git :: struct { } rolling_parent := make(dyn_str); - path := string.split(actual_dest, '/'); + path := string.split(actual_dest, os.PATH_SEP); for path[0 .. path.length-1] { string.append(&rolling_parent, it); - string.append(&rolling_parent, "/"); + string.append(&rolling_parent, os.PATH_SEP); if !os.dir_exists(rolling_parent) { os.dir_create(rolling_parent); diff --git a/shared/include/small_windows.h b/shared/include/small_windows.h index a3c4924a..edf5a5e8 100644 --- a/shared/include/small_windows.h +++ b/shared/include/small_windows.h @@ -469,3 +469,6 @@ GB_DLL_IMPORT BOOL WINAPI WaitOnAddress(volatile void * Address, void * compareA GB_DLL_IMPORT DWORD GetCurrentDirectory(DWORD nBufferLength, char *lpBuffer); GB_DLL_IMPORT BOOL SetCurrentDirectory(char *lpPathName); + +GB_DLL_IMPORT DWORD GetFileAttributesA(char *lpPathName); +GB_DLL_IMPORT BOOL SetFileAttributesA(char *lpPathName, DWORD attrs); \ No newline at end of file -- 2.25.1