MCPcopy Create free account
hub / github.com/Tencent/MMKV / isDiskOfMMAPFileCorrupted

Function isDiskOfMMAPFileCorrupted

Core/MemoryFile.cpp:690–712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

688
689#ifndef MMKV_APPLE
690bool 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
715std::optional<MMKVPath_t> getUniqueFileName(const MMKVPath_t &folder, const MMKVPath_t &prefix) {

Callers 1

checkFileHasDiskErrorMethod · 0.70

Calls 2

getFdMethod · 0.45
cleanMayflyFDMethod · 0.45

Tested by

no test coverage detected