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

Method isFileValid

Core/MMKV_IO.cpp:1654–1700  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1652}
1653
1654bool MMKV::isFileValid(const string &mmapID, const MMKVPath_t *relatePath) {
1655 if (!g_instanceLock) {
1656 return false;
1657 }
1658 SCOPED_LOCK(g_instanceLock);
1659
1660 std::string realID, mmapKey;
1661 auto [kvPath, crcPath] = getStorage(mmapID, relatePath, realID, mmapKey);
1662 if (kvPath.empty()) {
1663 return true;
1664 }
1665 if (crcPath.empty()) {
1666 return false;
1667 }
1668
1669 uint32_t crcFile = 0;
1670 MMBuffer *data = readWholeFile(crcPath);
1671 if (data) {
1672 if (data->getPtr()) {
1673 MMKVMetaInfo metaInfo;
1674 metaInfo.read(data->getPtr());
1675 crcFile = metaInfo.m_crcDigest;
1676 }
1677 delete data;
1678 } else {
1679 return false;
1680 }
1681
1682 uint32_t crcDigest = 0;
1683 MMBuffer *fileData = readWholeFile(kvPath);
1684 if (fileData) {
1685 if (fileData->getPtr() && (fileData->length() >= Fixed32Size)) {
1686 uint32_t actualSize = 0;
1687 memcpy(&actualSize, fileData->getPtr(), Fixed32Size);
1688 if (actualSize > (fileData->length() - Fixed32Size)) {
1689 delete fileData;
1690 return false;
1691 }
1692
1693 crcDigest = (uint32_t) CRC32(0, (const uint8_t *) fileData->getPtr() + Fixed32Size, (uint32_t) actualSize);
1694 }
1695 delete fileData;
1696 return crcFile == crcDigest;
1697 } else {
1698 return false;
1699 }
1700}
1701
1702bool MMKV::removeStorage(const std::string &mmapID, const MMKVPath_t *relatePath) {
1703 if (!g_instanceLock) {

Callers 12

loadFromFileMethod · 0.45
partialLoadFromFileMethod · 0.45
checkFileHasDiskErrorMethod · 0.45
loadMetaInfoAndCheckMethod · 0.45
checkLoadDataMethod · 0.45
readActualSizeMethod · 0.45
writeActualSizeMethod · 0.45
importFromMethod · 0.45
removeStorageMethod · 0.45
enableAutoKeyExpireMethod · 0.45
disableAutoKeyExpireMethod · 0.45

Calls 3

getStorageFunction · 0.85
readMethod · 0.80
readWholeFileFunction · 0.70

Tested by

no test coverage detected