From 745577c4734331280942d05dd1b9db55320e1127 Mon Sep 17 00:00:00 2001 From: fartsicle Date: Tue, 25 Aug 2026 14:07:17 -0400 Subject: [PATCH] Fix sharing violations in nob_needs_rebuild on Windows --- nob.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/nob.h b/nob.h index 2bdb16b..98782bf 100644 --- a/nob.h +++ b/nob.h @@ -2461,7 +2461,14 @@ NOBDEF int nob_needs_rebuild(const char *output_path, const char **input_paths, #ifdef _WIN32 BOOL bSuccess; - HANDLE output_path_fd = CreateFile(output_path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); + HANDLE output_path_fd = CreateFile( + output_path, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_READONLY, + NULL); if (output_path_fd == INVALID_HANDLE_VALUE) { // NOTE: if output does not exist it 100% must be rebuilt if (GetLastError() == ERROR_FILE_NOT_FOUND) return 1; @@ -2478,7 +2485,14 @@ NOBDEF int nob_needs_rebuild(const char *output_path, const char **input_paths, for (size_t i = 0; i < input_paths_count; ++i) { const char *input_path = input_paths[i]; - HANDLE input_path_fd = CreateFile(input_path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); + HANDLE input_path_fd = CreateFile( + input_path, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_READONLY, + NULL); if (input_path_fd == INVALID_HANDLE_VALUE) { // NOTE: non-existing input is an error cause it is needed for building in the first place nob_log(NOB_ERROR, "Could not open file %s: %s", input_path, nob_win32_error_message(GetLastError()));