| 1700 | } |
| 1701 | |
| 1702 | bool MMKV::removeStorage(const std::string &mmapID, const MMKVPath_t *relatePath) { |
| 1703 | if (!g_instanceLock) { |
| 1704 | return false; |
| 1705 | } |
| 1706 | SCOPED_LOCK(g_instanceLock); |
| 1707 | |
| 1708 | std::string realID, mmapKey; |
| 1709 | auto [kvPath, crcPath] = getStorage(mmapID, relatePath, realID, mmapKey); |
| 1710 | if (kvPath.empty() && crcPath.empty()) { |
| 1711 | return false; |
| 1712 | } |
| 1713 | MMKVInfo("remove storage [%s]", realID.c_str()); |
| 1714 | |
| 1715 | if (crcPath.empty()) { |
| 1716 | deleteFile(kvPath); |
| 1717 | return true; |
| 1718 | } |
| 1719 | |
| 1720 | File crcFile(crcPath, OpenFlag::ReadOnly); |
| 1721 | if (!crcFile.isFileValid()) { |
| 1722 | deleteFile(kvPath); |
| 1723 | return true; |
| 1724 | } |
| 1725 | FileLock fileLock(crcFile.getFd()); |
| 1726 | InterProcessLock lock(&fileLock, ExclusiveLockType); |
| 1727 | SCOPED_LOCK(&lock); |
| 1728 | |
| 1729 | auto itr = g_instanceDic->find(mmapKey); |
| 1730 | if (itr != g_instanceDic->end()) { |
| 1731 | itr->second->close(); |
| 1732 | // itr is not valid after this |
| 1733 | } |
| 1734 | |
| 1735 | deleteFile(kvPath); |
| 1736 | deleteFile(crcPath); |
| 1737 | |
| 1738 | return true; |
| 1739 | } |
| 1740 | |
| 1741 | bool MMKV::checkExist(const std::string &mmapID, const MMKVPath_t *relatePath) { |
| 1742 | if (!g_instanceLock) { |
nothing calls this directly
no test coverage detected