Win32: Better Error Handling in BLI_file_attributes

After Win32 API call GetFileAttributesW, check for
INVALID_FILE_ATTRIBUTES, which is returned on error,
usually if file not found.

See D17176 for more details.

Differential Revision: https://developer.blender.org/D17176

Reviewed by Ray Molenkamp
This commit is contained in:
Harley Acheson
2023-02-02 08:01:43 -08:00
parent 7208938707
commit fc2a64e21a

View File

@@ -209,7 +209,14 @@ eFileAttributes BLI_file_attributes(const char *path)
if (conv_utf_8_to_16(path, wline, ARRAY_SIZE(wline)) != 0) {
return ret;
}
DWORD attr = GetFileAttributesW(wline);
BLI_assert_msg(attr != INVALID_FILE_ATTRIBUTES,
"BLI_file_attributes should only be called on existing files.");
if (attr == INVALID_FILE_ATTRIBUTES) {
return ret;
}
if (attr & FILE_ATTRIBUTE_READONLY) {
ret |= FILE_ATTR_READONLY;
}