mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-25 11:34:55 +00:00
Fix rename for Windows users
Turns out, we're using copy instead of rename for a reason, and that same reason came up when adding the remove call. Also adds a log for the sceKernelWrite issue, since that's definitely a hack that needs to be debugged.
This commit is contained in:
parent
bfbe1d4908
commit
4c881f6e40
@ -301,6 +301,9 @@ s64 PS4_SYSV_ABI write(s32 fd, const void* buf, size_t nbytes) {
|
|||||||
expected_file_size += bytes_written;
|
expected_file_size += bytes_written;
|
||||||
auto actual_file_size = file->f.GetSize();
|
auto actual_file_size = file->f.GetSize();
|
||||||
if (expected_file_size != actual_file_size) {
|
if (expected_file_size != actual_file_size) {
|
||||||
|
LOG_WARNING(Kernel_Fs,
|
||||||
|
"Unexpected behavior from fwrite. Expected size {:#x}, actual size {:#x}",
|
||||||
|
expected_file_size, actual_file_size);
|
||||||
file->f.SetSize(expected_file_size);
|
file->f.SetSize(expected_file_size);
|
||||||
}
|
}
|
||||||
return bytes_written;
|
return bytes_written;
|
||||||
@ -760,8 +763,24 @@ s32 PS4_SYSV_ABI posix_rename(const char* from, const char* to) {
|
|||||||
*__Error() = POSIX_ENOTEMPTY;
|
*__Error() = POSIX_ENOTEMPTY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On Windows, std::filesystem::rename will error if the file has been opened before.
|
||||||
std::filesystem::copy(src_path, dst_path, std::filesystem::copy_options::overwrite_existing);
|
std::filesystem::copy(src_path, dst_path, std::filesystem::copy_options::overwrite_existing);
|
||||||
std::filesystem::remove(src_path);
|
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||||
|
auto file = h->GetFile(src_path);
|
||||||
|
if (file) {
|
||||||
|
// We need to force ReadWrite if the file had Write access before
|
||||||
|
// Otherwise f.Open will clear the file contents.
|
||||||
|
auto access_mode = file->f.GetAccessMode() == Common::FS::FileAccessMode::Write
|
||||||
|
? Common::FS::FileAccessMode::ReadWrite
|
||||||
|
: file->f.GetAccessMode();
|
||||||
|
file->f.Close();
|
||||||
|
std::filesystem::remove(src_path);
|
||||||
|
file->f.Open(dst_path, access_mode);
|
||||||
|
} else {
|
||||||
|
std::filesystem::remove(src_path);
|
||||||
|
}
|
||||||
|
|
||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user