Check if file exists before calling platform-specific code

Bloodborne checks if a file doesn't exist using open, checking if it specifically failed with error code ENOENT. To avoid working with platform-specific errnos, add a proper error return for if the file doesn't exist.
Fixes a regression in Bloodborne.
This commit is contained in:
Stephen Miller 2025-02-20 17:57:31 -06:00
parent b52b6ae04b
commit 6c2329eadf

View File

@ -118,10 +118,11 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
} else { } else {
file->m_guest_name = path; file->m_guest_name = path;
file->m_host_name = mnt->GetHostPath(file->m_guest_name); file->m_host_name = mnt->GetHostPath(file->m_guest_name);
bool exists = std::filesystem::exists(file->m_host_name);
int e = 0; int e = 0;
if (create) { if (create) {
if (excl && std::filesystem::exists(file->m_host_name)) { if (excl && exists) {
// Error if file exists // Error if file exists
h->DeleteHandle(handle); h->DeleteHandle(handle);
*__Error() = POSIX_EEXIST; *__Error() = POSIX_EEXIST;
@ -131,6 +132,13 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
Common::FS::IOFile out(file->m_host_name, Common::FS::FileAccessMode::Write); Common::FS::IOFile out(file->m_host_name, Common::FS::FileAccessMode::Write);
} }
if (!exists) {
// File to open doesn't exist, return ENOENT
h->DeleteHandle(handle);
*__Error() = POSIX_ENOENT;
return -1;
}
if (read) { if (read) {
// Read only // Read only
e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::Read); e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::Read);