1
0
mirror of https://github.com/pbatard/rufus.git synced 2026-10-24 02:28:58 +03:00

[net] Don't remove an existing file in case of a download failure

This commit is contained in:
Pete Batard
2026-09-08 16:50:01 +01:00
parent 482cdb53e7
commit b4a62a4e01
2 changed files with 17 additions and 6 deletions

View File

@@ -173,7 +173,7 @@ uint64_t DownloadToFileOrBufferEx(const char* url, const char* file, const char*
const char* accept_types[] = {"*/*\0", NULL};
const char* short_name;
unsigned char buf[DOWNLOAD_BUFFER_SIZE];
char hostname[64], urlpath[128], strsize[32];
char hostname[64], urlpath[128], strsize[32], *bak_file = NULL;
BOOL r = FALSE;
DWORD dwSize, dwWritten, dwDownloaded;
HANDLE hFile = INVALID_HANDLE_VALUE;
@@ -198,6 +198,13 @@ uint64_t DownloadToFileOrBufferEx(const char* url, const char* file, const char*
uprintf("Downloading %s", url);
}
// If an old file with the same name exists, rename it so we can restore it in case of failure
if (file != NULL && PathFileExistsU((char*)file) && (bak_file = calloc(1, strlen(file) + 6)) != NULL) {
strcpy(bak_file, file);
strcat(bak_file, ".bak");
MoveFileU(file, bak_file);
}
if ( (!InternetCrackUrlA(url, (DWORD)safe_strlen(url), 0, &UrlParts))
|| (UrlParts.lpszHostName == NULL) || (UrlParts.lpszUrlPath == NULL)) {
uprintf("Unable to decode URL: %s", WindowsErrorString());
@@ -327,8 +334,12 @@ out:
if (!r) {
if (file != NULL)
DeleteFileU(file);
if (bak_file != NULL)
MoveFileU(bak_file, file);
if (buffer != NULL)
safe_free(*buffer);
} else if (bak_file != NULL) {
DeleteFileU(bak_file);
}
if (hRequest)
InternetCloseHandle(hRequest);

View File

@@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 4.15.2402"
CAPTION "Rufus 4.15.2403"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@@ -409,8 +409,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,15,2402,0
PRODUCTVERSION 4,15,2402,0
FILEVERSION 4,15,2403,0
PRODUCTVERSION 4,15,2403,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -428,13 +428,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.15.2402"
VALUE "FileVersion", "4.15.2403"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2026 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.15.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.15.2402"
VALUE "ProductVersion", "4.15.2403"
END
END
BLOCK "VarFileInfo"