From d8c76d2f348b1521e55ad73bb155470d63ee1b75 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 26 Sep 2024 19:33:50 -0400
Subject: [PATCH] filesystem: POSIX SDL_SYS_CopyFile shouldn't use a temp file.
Fixes #10957.
---
src/filesystem/posix/SDL_sysfsops.c | 23 +++--------------------
1 file changed, 3 insertions(+), 20 deletions(-)
diff --git a/src/filesystem/posix/SDL_sysfsops.c b/src/filesystem/posix/SDL_sysfsops.c
index e589f438b6360..5b199c7f84bff 100644
--- a/src/filesystem/posix/SDL_sysfsops.c
+++ b/src/filesystem/posix/SDL_sysfsops.c
@@ -83,23 +83,18 @@ bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath)
bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath)
{
char *buffer = NULL;
- char *tmppath = NULL;
SDL_IOStream *input = NULL;
SDL_IOStream *output = NULL;
const size_t maxlen = 4096;
size_t len;
bool result = false;
- if (SDL_asprintf(&tmppath, "%s.tmp", newpath) < 0) {
- goto done;
- }
-
input = SDL_IOFromFile(oldpath, "rb");
if (!input) {
goto done;
}
- output = SDL_IOFromFile(tmppath, "wb");
+ output = SDL_IOFromFile(newpath, "wb");
if (!output) {
goto done;
}
@@ -125,28 +120,16 @@ bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath)
goto done;
}
- if (!SDL_CloseIO(output)) {
- output = NULL; // it's gone, even if it failed.
- goto done;
- }
- output = NULL;
-
- if (!SDL_RenamePath(tmppath, newpath)) {
- SDL_RemovePath(tmppath);
- goto done;
- }
-
- result = true;
+ result = SDL_CloseIO(output);
+ output = NULL; // it's gone, even if it failed.
done:
if (output) {
SDL_CloseIO(output);
- SDL_RemovePath(tmppath);
}
if (input) {
SDL_CloseIO(input);
}
- SDL_free(tmppath);
SDL_free(buffer);
return result;