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

Function isDiskOfMMAPFileCorrupted

Core/MemoryFile_OSX.cpp:148–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148bool isDiskOfMMAPFileCorrupted(MemoryFile *file, bool &needReportReadFail) {
149 uint32_t info;
150 auto fd = file->getFd();
151 auto path = file->getPath().c_str();
152
153 auto oldPos = lseek(fd, 0, SEEK_CUR);
154 lseek(fd, 0, SEEK_SET);
155 auto size = read(fd, &info, sizeof(info));
156 auto err = errno;
157 lseek(fd, oldPos, SEEK_SET);
158
159 if (size <= 0) {
160 needReportReadFail = true;
161 MMKVError("fail to read [%s] from fd [%d], errno: %d (%s)", path, fd, err, strerror(err));
162 if (err == EDEVERR || err == EILSEQ || err == EINVAL || err == ENXIO) {
163 MMKVWarning("file fail to read, consider it illegal, delete now: [%s]", path);
164 return true;
165 }
166 }
167 file->cleanMayflyFD();
168 return false;
169}
170
171} // namespace mmkv
172

Callers

nothing calls this directly

Calls 2

getFdMethod · 0.45
cleanMayflyFDMethod · 0.45

Tested by

no test coverage detected