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

Function backupOneToDirectoryByFilePath

Core/MMKV.cpp:1246–1270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1244// backup
1245
1246static bool backupOneToDirectoryByFilePath(const string &mmapKey, const MMKVPath_t &srcPath, const MMKVPath_t &dstPath) {
1247 File crcFile(srcPath, OpenFlag::ReadOnly);
1248 if (!crcFile.isFileValid()) {
1249 return false;
1250 }
1251
1252 bool ret;
1253 {
1254 const auto &dstUTF8Path = MMKVPath_t2String(dstPath);
1255 MMKVInfo("backup one mmkv[%s] from [%s] to [%s]", mmapKey.c_str(), crcFile.getUTF8Path().c_str(),
1256 dstUTF8Path.c_str());
1257 FileLock fileLock(crcFile.getFd());
1258 InterProcessLock lock(&fileLock, SharedLockType);
1259 SCOPED_LOCK(&lock);
1260
1261 ret = copyFile(srcPath, dstPath);
1262 if (ret) {
1263 auto srcCRCPath = srcPath + CRC_SUFFIX;
1264 auto dstCRCPath = dstPath + CRC_SUFFIX;
1265 ret = copyFile(srcCRCPath, dstCRCPath);
1266 }
1267 MMKVInfo("finish backup one mmkv[%s]", mmapKey.c_str());
1268 }
1269 return ret;
1270}
1271
1272bool MMKV::backupOneToDirectory(const string &mmapKey, const MMKVPath_t &dstPath, const MMKVPath_t &srcPath, bool compareFullPath) {
1273 if (!g_instanceLock) {

Callers 1

backupOneToDirectoryMethod · 0.85

Calls 4

MMKVPath_t2StringFunction · 0.85
copyFileFunction · 0.70
isFileValidMethod · 0.45
getFdMethod · 0.45

Tested by

no test coverage detected