Save data: fix nullptr & concurrency file write

This commit is contained in:
Vinicius Rangel 2024-09-23 20:52:11 -03:00
parent 10d29cc007
commit 8399cb6b74
No known key found for this signature in database
GPG key ID: A5B154D904B761D9
3 changed files with 10 additions and 5 deletions

View file

@ -102,7 +102,12 @@ bool PSF::Encode(const std::filesystem::path& filepath) const {
last_write = std::filesystem::file_time_type::clock::now();
const auto psf_buffer = Encode();
return file.Write(psf_buffer) == psf_buffer.size();
const size_t written = file.Write(psf_buffer);
if (written != psf_buffer.size()) {
LOG_ERROR(Core, "Failed to write PSF file. Written {} Expected {}", written,
psf_buffer.size());
}
return written == psf_buffer.size();
}
std::vector<u8> PSF::Encode() const {

View file

@ -119,7 +119,7 @@ static void BackupThreadBody() {
std::scoped_lock lk{g_backup_queue_mutex};
g_backup_queue.front().done = true;
}
std::this_thread::sleep_for(std::chrono::seconds(10)); // Don't backup too often
std::this_thread::sleep_for(std::chrono::seconds(5)); // Don't backup too often
{
std::scoped_lock lk{g_backup_queue_mutex};
g_backup_queue.pop_front();

View file

@ -485,14 +485,14 @@ static Error Umount(const OrbisSaveDataMountPoint* mountPoint, bool call_backup
if (instance.has_value()) {
const auto& slot_name = instance->GetMountPoint();
if (slot_name == mount_point_str) {
// TODO: check if is busy
instance->Umount();
if (call_backup) {
Backup::StartThread();
Backup::NewRequest(instance->GetUserId(), instance->GetTitleId(),
instance->GetDirName(),
OrbisSaveDataEventType::UMOUNT_BACKUP);
}
// TODO: check if is busy
instance->Umount();
instance.reset();
return Error::OK;
}
@ -581,10 +581,10 @@ Error PS4_SYSV_ABI sceSaveDataCheckBackupData(const OrbisSaveDataCheckBackupData
LOG_INFO(Lib_SaveData, "called with invalid parameter");
return Error::PARAMETER;
}
LOG_DEBUG(Lib_SaveData, "called with titleId={}", check->titleId->data.to_view());
const std::string_view title{check->titleId != nullptr ? std::string_view{check->titleId->data}
: std::string_view{g_game_serial}};
LOG_DEBUG(Lib_SaveData, "called with titleId={}", title);
const auto save_path =
SaveInstance::MakeDirSavePath(check->userId, title, check->dirName->data);