| 624 | } |
| 625 | |
| 626 | bool isDiskOfMMAPFileCorrupted(MemoryFile *file, bool &needReportReadFail) { |
| 627 | // make sure the file is valid |
| 628 | __try { |
| 629 | auto filesize = file->getFileSize(); |
| 630 | volatile uint8_t* ptr = (uint8_t*) file->getMemory(); |
| 631 | // check the head of every page |
| 632 | for (size_t index = 0; index < filesize; index += DEFAULT_MMAP_SIZE) { |
| 633 | volatile uint8_t byte = ptr[index]; |
| 634 | MMKVDebug("%zu byte of the file: 0x%x", index, byte); |
| 635 | } |
| 636 | // check the very last byte of the file |
| 637 | if (filesize > 1) { |
| 638 | volatile uint8_t byte = ptr[filesize - 1]; |
| 639 | MMKVDebug("%zu byte of the file: 0x%x", filesize - 1, byte); |
| 640 | } |
| 641 | } |
| 642 | __except ((GetExceptionCode() == EXCEPTION_IN_PAGE_ERROR || GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) |
| 643 | ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { |
| 644 | needReportReadFail = true; |
| 645 | DWORD errorCode = GetExceptionCode(); |
| 646 | MMKVError("fail to mmap [%s], %d", file->getUTF8Path().c_str(), errorCode); |
| 647 | return true; |
| 648 | } |
| 649 | return false; |
| 650 | } |
| 651 | |
| 652 | bool deleteFile(const MMKVPath_t &path) { |
| 653 | if (!DeleteFile(path.c_str())) { |
nothing calls this directly
no test coverage detected