| 1244 | // backup |
| 1245 | |
| 1246 | static 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 | |
| 1272 | bool MMKV::backupOneToDirectory(const string &mmapKey, const MMKVPath_t &dstPath, const MMKVPath_t &srcPath, bool compareFullPath) { |
| 1273 | if (!g_instanceLock) { |
no test coverage detected