Delete temporary files before attempting to rename (Windows and some Unix fixes).

This commit is contained in:
Steve 2019-12-01 11:56:49 +00:00
parent e8a8e87666
commit 2fa40d8933
3 changed files with 14 additions and 4 deletions

View File

@ -1,5 +1,5 @@
VERSION = 1.2
REVISION = 0
REVISION = 1
LOCALE_MO = $(patsubst %.po,%.mo,$(wildcard locale/*.po))
OUT = bin

View File

@ -100,7 +100,12 @@ static void saveGameAndWorld(void)
src = buildFormattedString("%s/%d/%s.json.tmp", app.saveDir, game.saveSlot, world.id);
dest = buildFormattedString("%s/%d/%s.json", app.saveDir, game.saveSlot, world.id);
renameFile(src, dest);
if (!renameFile(src, dest))
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save file '%s'", dest);
exit(1);
}
free(src);
free(dest);
@ -108,7 +113,12 @@ static void saveGameAndWorld(void)
src = buildFormattedString("%s/%d/game.json.tmp", app.saveDir, game.saveSlot);
dest = buildFormattedString("%s/%d/game.json", app.saveDir, game.saveSlot, world.id);
renameFile(src, dest);
if (!renameFile(src, dest))
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save file '%s'", dest);
exit(1);
}
free(src);
free(dest);

View File

@ -202,7 +202,7 @@ int deleteFile(char *path)
int renameFile(char *src, char *dest)
{
return rename(src, dest) == 0;
return deleteFile(dest) && rename(src, dest) == 0;
}
static int stringComparator(const void *a, const void *b)