Skip to content

Stop find_c aborting on directory entries#4

Merged
pathanin merged 1 commit into
masterfrom
fix-filesearch-directory-file-size
Jul 25, 2026
Merged

Stop find_c aborting on directory entries#4
pathanin merged 1 commit into
masterfrom
fix-filesearch-directory-file-size

Conversation

@pathanin

@pathanin pathanin commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Fixes a macOS-only crash: opening the build list with a sub-folder under Builds/ throws

In 'OnFrame': C++ exception:
filesystem error: in file_size: Is a directory [".../src/Builds/testpob"]
stack traceback:
[C]: in function 'NewFileSearch'
Modules/BuildListHelpers.lua:63: in function 'ScanFolder'

Cause

find_c::FindFirst/FindNext called iter->file_size() — the throwing overload — on every entry that matched the glob. directory_entry::file_size() has no defined result for a directory: MSVC returns the size cached by FindFirstFile (0) and never throws, libc++ calls stat and throws. So the code is correct on Windows and fatal everywhere else.

The throw happens in find_c, before NewFileSearch's findDirectories filter at ui_api.cpp:1354, so it is not limited to directory searches — any NewFileSearch(dir.."*") dies if dir holds a sub-directory. Affected call sites in PoB-PoE2: Modules/BuildListHelpers.lua:63, Classes/FolderListControl.lua:46,82, Classes/BuildListControl.lua:144, Modules/Main.lua:1583-1634 (folder copy/delete walks), Export/Main.lua:712-763.

Change

Query metadata through the error_code overloads and report 0 for a directory — the value Windows already produces, so no caller sees a behaviour change. is_directory() and last_write_time() get the same treatment: they fail out of the same status() call, so an unreadable or dangling entry aborted the process by the identical route.

Verification

Windows CI cannot cover this — the divergence is libc++ vs MSVC. Verified locally against the shipped arm64 dylib with a probe that calls find_c::FindFirst/FindNext directly over src/Builds/, which contains one sub-folder (testpob) and two files:

dylib result
before RESULT: THREW - filesystem error: in file_size: Is a directory [.../Builds/testpob] on the first entry
after testpob dir=1 size=0, .DS_Store dir=0 size=8196, ~~temp~~.xml dir=0 size=53075; *.xml glob returns 1; recursing into testpob/* returns 2; no exception

Built with the standard arm64-osx-dynamic config; incremental relink, LuaJIT untouched so the soname is unchanged. runtime/libSimpleGraphic.dylib restaged with @loader_path re-added; all 9 @rpath deps resolve. Backup at ~/Documents/pob-runtime-backup-2026-07-25/.

A failed last_write_time() returns file_time_type::min(), whose negative count would wrap to a huge value in find_c::modified (unsigned long long) and sort the entry to the top of the build list's "Sort by Last Edited"; that reports 0 instead.

directory_entry::file_size() has no defined result for a directory. MSVC
returns the size cached by FindFirstFile (0), so on Windows the throwing
overloads used here never fire; libc++ calls stat and throws instead, so
on macOS every NewFileSearch over a folder that contains a subdirectory
died with "filesystem error: in file_size: Is a directory" before the
binding could even apply its findDirectories filter. The build list was
the visible casualty - one sub-folder under Builds/ made the startup
screen unreachable - but Main.lua's folder copy/delete walks and the
Export scripts glob directories the same way.

Query the entry through the error_code overloads and report 0 for a
directory, matching what Windows already returns. is_directory() and
last_write_time() get the same treatment: they fail out of the same
status() call, so an unreadable or dangling entry took the process down
by the identical route.
@pathanin
pathanin force-pushed the fix-filesearch-directory-file-size branch from 7ceff97 to 6b4cf07 Compare July 25, 2026 09:22
@pathanin

Copy link
Copy Markdown
Owner Author

End-to-end confirmed on the staged arm64 runtime: the build list renders the testpob folder row, opens it, and lists both builds inside. That closes the one gap the find_c probe could not cover.

@pathanin
pathanin merged commit fa7c335 into master Jul 25, 2026
2 checks passed
@pathanin
pathanin deleted the fix-filesearch-directory-file-size branch July 25, 2026 09:48
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