fix tryAtomicRename() with src == dst bug

This commit is contained in:
guoling
2024-12-02 15:15:18 +08:00
parent 8d6377667c
commit 20b68dbc71
4 changed files with 19 additions and 12 deletions
+4 -1
View File
@@ -72,6 +72,10 @@ bool tryAtomicRename(const MMKVPath_t &srcPath, const MMKVPath_t &dstPath) {
MMKVWarning("fail on syscall(SYS_renameat2) [%s] to [%s], %d(%s)", srcPath.c_str(), dstPath.c_str(), errno,
strerror(errno));
}
if (renamed && (srcPath != dstPath)) {
::unlink(srcPath.c_str());
}
#endif // SYS_renameat2 && !MMKV_OHOS
if (!renamed) {
@@ -81,7 +85,6 @@ bool tryAtomicRename(const MMKVPath_t &srcPath, const MMKVPath_t &dstPath) {
}
}
::unlink(srcPath.c_str());
return true;
}