Skip to content

Commit a5872e1

Browse files
committed
Rename() consistency: don't allow newPath to exist
1 parent ba1922e commit a5872e1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Source/Managers/LuaMan.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,10 +1200,15 @@ namespace RTE {
12001200
fullOldPath = GetCaseInsensitiveFullPath(fullOldPath);
12011201
fullNewPath = GetCaseInsensitiveFullPath(fullNewPath);
12021202
#endif
1203-
try {
1204-
std::filesystem::rename(fullOldPath, fullNewPath);
1205-
return true;
1206-
} catch (const std::filesystem::filesystem_error &e) {}
1203+
// Ensures parity between Linux which can overwrite an empty directory, while Windows can't
1204+
// Ensures parity between Linux which can't rename a directory to a newPath that is a file in order to overwrite it, while Windows can
1205+
if (!std::filesystem::exists(fullNewPath))
1206+
{
1207+
try {
1208+
std::filesystem::rename(fullOldPath, fullNewPath);
1209+
return true;
1210+
} catch (const std::filesystem::filesystem_error &e) {}
1211+
}
12071212
}
12081213
g_ConsoleMan.PrintString("ERROR: Failed to rename oldPath " + oldPath + " to newPath " + newPath);
12091214
return false;

0 commit comments

Comments
 (0)