| 688 | |
| 689 | #ifndef MMKV_APPLE |
| 690 | bool isDiskOfMMAPFileCorrupted(MemoryFile *file, bool &needReportReadFail) { |
| 691 | // TODO: maybe we need reading a larger chunk than 4 byte in Android/Linux |
| 692 | uint32_t info; |
| 693 | auto fd = file->getFd(); |
| 694 | auto path = file->getPath().c_str(); |
| 695 | |
| 696 | auto oldPos = lseek(fd, 0, SEEK_CUR); |
| 697 | lseek(fd, 0, SEEK_SET); |
| 698 | auto size = read(fd, &info, sizeof(info)); |
| 699 | auto err = errno; |
| 700 | lseek(fd, oldPos, SEEK_SET); |
| 701 | |
| 702 | if (size <= 0) { |
| 703 | needReportReadFail = true; |
| 704 | MMKVError("fail to read [%s] from fd [%d], errno: %d (%s)", path, fd, err, strerror(err)); |
| 705 | if (err == EIO || err == EILSEQ || err == EINVAL || err == ENXIO) { |
| 706 | MMKVWarning("file fail to read, consider it illegal, delete now: [%s]", path); |
| 707 | return true; |
| 708 | } |
| 709 | } |
| 710 | file->cleanMayflyFD(); |
| 711 | return false; |
| 712 | } |
| 713 | #endif |
| 714 | |
| 715 | std::optional<MMKVPath_t> getUniqueFileName(const MMKVPath_t &folder, const MMKVPath_t &prefix) { |
no test coverage detected