luaur_cli_lib/functions/is_file.rs
1pub fn is_file(path: &str) -> bool {
2 // Probe the filesystem through `std::fs` (like `is_directory`) rather than
3 // raw Win32 wide-char FFI. The previous Windows path widened via
4 // `from_utf_8` — whose UTF-16 buffer is NOT NUL-terminated — and handed it
5 // to `GetFileAttributesW`, which reads until a NUL: undefined behaviour that
6 // made existing files intermittently report as missing (e.g. require could
7 // not descend into subdirectories). `symlink_metadata` + `is_file()` mirrors
8 // the POSIX `lstat`/`S_IFREG` check and is correct on every platform.
9 std::fs::symlink_metadata(path)
10 .map(|meta| meta.is_file())
11 .unwrap_or(false)
12}