Skip to content

needs_rebuild: don't open files on Windows when checking timestamps - #269

Open
zzyxyz666 wants to merge 1 commit into
tsoding:mainfrom
zzyxyz666:needs-rebuild-no-open-files
Open

needs_rebuild: don't open files on Windows when checking timestamps#269
zzyxyz666 wants to merge 1 commit into
tsoding:mainfrom
zzyxyz666:needs-rebuild-no-open-files

Conversation

@zzyxyz666

@zzyxyz666 zzyxyz666 commented Aug 19, 2026

Copy link
Copy Markdown

nob_needs_rebuild() opened files with CreateFile(path, GENERIC_READ, 0, NULL, ...) on Windows.
dwShareMode = 0 is an exclusive open, so any other process holding the file (an editor, clangd,
an antivirus scanner) made nob fail with ERROR_SHARING_VIOLATION, while the POSIX stat() path was
unaffected. I hit this in practice while editing in VSCode: the C/C++ extension (clangd) keeps the
source files open, so nob failed until the language server released the file.

Use GetFileAttributesExA() which reads the file metadata without opening the file, matching the
POSIX semantics and the existing Windows implementations of nob_file_exists() and
nob_get_file_type(). Behavior is otherwise unchanged.

Add tests/needs_rebuild_locked_file which locks an input file and asserts needs_rebuild() still
returns the correct result.

nob_needs_rebuild() opened files with CreateFile(path, GENERIC_READ, 0,
NULL, ...) on Windows. dwShareMode = 0 is an exclusive open, so any other
process holding the file (an editor, clangd, an antivirus scanner) made
nob fail with ERROR_SHARING_VIOLATION, while the POSIX stat() path was
unaffected.

Use GetFileAttributesExA() which reads the file metadata without opening
the file, matching the POSIX semantics and the existing Windows
implementations of nob_file_exists() and nob_get_file_type(). Behavior is
otherwise unchanged.

Add tests/needs_rebuild_locked_file which locks an input file and asserts
needs_rebuild() still returns the correct result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant