| 404 | } |
| 405 | |
| 406 | s32 write_request(SaveGame::Request &rr) |
| 407 | { |
| 408 | DynamicString temp_filename(default_allocator()); |
| 409 | File *file = _filesystem.open_temporary(temp_filename); |
| 410 | CE_ENSURE(file != NULL); |
| 411 | if (!file->is_open()) { |
| 412 | _filesystem.close(*file); |
| 413 | return SaveError::IO_ERROR; |
| 414 | } |
| 415 | |
| 416 | const u32 size = rr.size; |
| 417 | |
| 418 | const s32 io_result = do_chunked_io(*file, rr.data, size, IO_WRITE, rr); |
| 419 | _filesystem.close(*file); |
| 420 | |
| 421 | if (io_result != SaveError::SUCCESS) { |
| 422 | os::delete_file(temp_filename.c_str()); |
| 423 | return io_result; |
| 424 | } |
| 425 | |
| 426 | DynamicString filename(default_allocator()); |
| 427 | _filesystem.absolute_path(filename, rr.basename); |
| 428 | |
| 429 | const RenameResult res = os::rename(temp_filename.c_str(), filename.c_str()); |
| 430 | if (res.error != RenameResult::SUCCESS) { |
| 431 | os::delete_file(temp_filename.c_str()); |
| 432 | return SaveError::IO_ERROR; |
| 433 | } |
| 434 | |
| 435 | return SaveError::SUCCESS; |
| 436 | } |
| 437 | |
| 438 | #if CROWN_PLATFORM_EMSCRIPTEN |
| 439 | /// Spins until @a pred returns true or exit is requested. |
nothing calls this directly
no test coverage detected