refactor: tr_loadFile() tr_saveFile() take a std::string_view filename arg (#2822)

* refactor: tr_saveFile takes a string_view

* refactor: tr_saveFile, tr_loadFile take string_view filename
This commit is contained in:
Charles Kerr
2022-03-25 19:31:27 -05:00
committed by GitHub
parent 1051160b99
commit 977b2a1bab
15 changed files with 102 additions and 86 deletions

View File

@@ -34,6 +34,7 @@
#include "torrent.h"
#include "tr-assert.h"
#include "tr-macros.h"
#include "tr-strbuf.h"
#include "utils.h"
#include "variant.h"
#include "version.h"
@@ -1439,11 +1440,17 @@ static void onBlocklistFetched(tr_web::FetchResponse const& web_response)
// tr_blocklistSetContent needs a source file,
// so save content into a tmpfile
auto const filename = tr_strvJoin(tr_sessionGetConfigDir(session), "blocklist.tmp");
auto const filename = tr_pathbuf{ session->config_dir, "/blocklist.tmp"sv };
tr_error* error = nullptr;
if (!tr_saveFile(filename, std::string_view{ std::data(content), std::size(content) }, &error))
if (!tr_saveFile(filename.sv(), content, &error))
{
tr_snprintf(result, sizeof(result), _("Couldn't save file \"%1$s\": %2$s"), filename.c_str(), error->message);
fmt::format_to_n(
result,
sizeof(result),
_("Couldn't save '{path}': {error} ({error_code})"),
fmt::arg("path", filename.sv()),
fmt::arg("error", error->message),
fmt::arg("error_code", error->code));
tr_error_clear(&error);
tr_idle_function_done(data, result);
return;