From d45e03bbff94cbcd5801395892adcf1f252858cc Mon Sep 17 00:00:00 2001 From: Ansariel Date: Sun, 9 Jun 2024 18:09:35 +0200 Subject: [PATCH] Since I stumbled over it: Use modern C++ to copy a file... --- indra/newview/llfloaterpreference.cpp | 36 +++++---------------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp index 825e48fb33..8a6e4a286b 100644 --- a/indra/newview/llfloaterpreference.cpp +++ b/indra/newview/llfloaterpreference.cpp @@ -156,6 +156,7 @@ #include "llviewershadermgr.h" #include "NACLantispam.h" #include "../llcrashlogger/llcrashlogger.h" +#include #if LL_WINDOWS #include #endif @@ -5272,38 +5273,13 @@ void LLPanelPreferenceSkins::refreshPreviewImage() // // Backup Settings -// copied from llxfer_file.cpp - Hopefully this will be part of LLFile some day -Zi -// added a safeguard so the destination file is only created when the source file exists -Zi -S32 copy_prefs_file(const std::string& from, const std::string& to) +static void copy_prefs_file(const std::string& from, const std::string& to) { - LL_WARNS() << "copying " << from << " to " << to << LL_ENDL; - S32 rv = 0; - LLFILE* in = LLFile::fopen(from, "rb"); /*Flawfinder: ignore*/ - if(!in) - { - LL_WARNS() << "couldn't open source file " << from << " - copy aborted." << LL_ENDL; - return -1; - } + LL_INFOS() << "Copying " << from << " to " << to << LL_ENDL; - LLFILE* out = LLFile::fopen(to, "wb"); /*Flawfinder: ignore*/ - if(!out) - { - fclose(in); - LL_WARNS() << "couldn't open destination file " << to << " - copy aborted." << LL_ENDL; - return -1; - } - - S32 read = 0; - const S32 COPY_BUFFER_SIZE = 16384; - U8 buffer[COPY_BUFFER_SIZE]; - while(((read = fread(buffer, 1, sizeof(buffer), in)) > 0) - && (fwrite(buffer, 1, read, out) == (U32)read)); /* Flawfinder : ignore */ - if(ferror(in) || ferror(out)) rv = -2; - - if(in) fclose(in); - if(out) fclose(out); - - return rv; + std::error_code ec; + if (!std::filesystem::copy_file(from, to, ec) || ec) + LL_WARNS() << "Couldn't copy file: " << ec.message() << LL_ENDL; } static LLPanelInjector t_pref_backup("panel_preference_backup");