mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
refactor: use fmt (#2758)
* deps: use fmt (8.1.1 tag) to build log strings Co-authored-by: Mike Gelfand <mikedld@mikedld.com>
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include "transmission.h"
|
||||
|
||||
#include "error-types.h"
|
||||
@@ -231,14 +233,18 @@ uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
|
||||
tr_error* my_error = nullptr;
|
||||
if (!tr_sys_path_get_info(path, 0, &info, &my_error))
|
||||
{
|
||||
tr_logAddError("Couldn't read \"%1$s\": %2$s", path, my_error->message);
|
||||
tr_logAddError(fmt::format(
|
||||
_("Couldn't read '{path}': {errmsg} ({errcode})"),
|
||||
fmt::arg("path", path),
|
||||
fmt::arg("errmsg", my_error->message),
|
||||
fmt::arg("errcode", my_error->code)));
|
||||
tr_error_propagate(error, &my_error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (info.type != TR_SYS_PATH_IS_FILE)
|
||||
{
|
||||
tr_logAddError("Couldn't read \"%1$s\": Not a regular file", path);
|
||||
tr_logAddError(fmt::format(_("Couldn't read '{path}': Not a regular file"), fmt::arg("path", path)));
|
||||
tr_error_set(error, TR_ERROR_EISDIR, "Not a regular file"sv);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -253,7 +259,11 @@ uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
|
||||
auto const fd = tr_sys_file_open(path, TR_SYS_FILE_READ | TR_SYS_FILE_SEQUENTIAL, 0, &my_error);
|
||||
if (fd == TR_BAD_SYS_FILE)
|
||||
{
|
||||
tr_logAddError("Couldn't read \"%1$s\": %2$s", path, my_error->message);
|
||||
tr_logAddError(fmt::format(
|
||||
_("Couldn't read '{path}': {errmsg} ({errcode})"),
|
||||
fmt::arg("path", path),
|
||||
fmt::arg("errmsg", my_error->message),
|
||||
fmt::arg("errcode", my_error->code)));
|
||||
tr_error_propagate(error, &my_error);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -261,7 +271,11 @@ uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
|
||||
auto* buf = static_cast<uint8_t*>(tr_malloc(info.size + 1));
|
||||
if (!tr_sys_file_read(fd, buf, info.size, nullptr, &my_error))
|
||||
{
|
||||
tr_logAddError("Couldn't read \"%1$s\": %2$s", path, my_error->message);
|
||||
tr_logAddError(fmt::format(
|
||||
_("Couldn't read '{path}': {errmsg} ({errcode})"),
|
||||
fmt::arg("path", path),
|
||||
fmt::arg("errmsg", my_error->message),
|
||||
fmt::arg("errcode", my_error->code)));
|
||||
tr_sys_file_close(fd, nullptr);
|
||||
tr_free(buf);
|
||||
tr_error_propagate(error, &my_error);
|
||||
@@ -283,14 +297,18 @@ bool tr_loadFile(std::vector<char>& setme, std::string const& path, tr_error** e
|
||||
tr_error* my_error = nullptr;
|
||||
if (!tr_sys_path_get_info(path_sz, 0, &info, &my_error))
|
||||
{
|
||||
tr_logAddError(_("Couldn't read \"%1$s\": %2$s"), path_sz, my_error->message);
|
||||
tr_logAddError(fmt::format(
|
||||
_("Couldn't read '{path}': {errmsg} ({errcode})"),
|
||||
fmt::arg("path", path),
|
||||
fmt::arg("errmsg", my_error->message),
|
||||
fmt::arg("errcode", my_error->code)));
|
||||
tr_error_propagate(error, &my_error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (info.type != TR_SYS_PATH_IS_FILE)
|
||||
{
|
||||
tr_logAddError(_("Couldn't read \"%1$s\": Not a regular file"), path_sz);
|
||||
tr_logAddError(fmt::format(_("Couldn't read '{path}': Not a regular file"), fmt::arg("path", path)));
|
||||
tr_error_set(error, TR_ERROR_EISDIR, "Not a regular file"sv);
|
||||
return false;
|
||||
}
|
||||
@@ -299,7 +317,11 @@ bool tr_loadFile(std::vector<char>& setme, std::string const& path, tr_error** e
|
||||
auto const fd = tr_sys_file_open(path_sz, TR_SYS_FILE_READ | TR_SYS_FILE_SEQUENTIAL, 0, &my_error);
|
||||
if (fd == TR_BAD_SYS_FILE)
|
||||
{
|
||||
tr_logAddError(_("Couldn't read \"%1$s\": %2$s"), path_sz, my_error->message);
|
||||
tr_logAddError(fmt::format(
|
||||
_("Couldn't read '{path}': {errmsg} ({errcode})"),
|
||||
fmt::arg("path", path),
|
||||
fmt::arg("errmsg", my_error->message),
|
||||
fmt::arg("errcode", my_error->code)));
|
||||
tr_error_propagate(error, &my_error);
|
||||
return false;
|
||||
}
|
||||
@@ -307,7 +329,11 @@ bool tr_loadFile(std::vector<char>& setme, std::string const& path, tr_error** e
|
||||
setme.resize(info.size);
|
||||
if (!tr_sys_file_read(fd, std::data(setme), info.size, nullptr, &my_error))
|
||||
{
|
||||
tr_logAddError(_("Couldn't read \"%1$s\": %2$s"), path_sz, my_error->message);
|
||||
tr_logAddError(fmt::format(
|
||||
_("Couldn't read '{path}': {errmsg} ({errcode})"),
|
||||
fmt::arg("path", path),
|
||||
fmt::arg("errmsg", my_error->message),
|
||||
fmt::arg("errcode", my_error->code)));
|
||||
tr_sys_file_close(fd, nullptr);
|
||||
tr_error_propagate(error, &my_error);
|
||||
return false;
|
||||
@@ -360,7 +386,7 @@ bool tr_saveFile(std::string const& filename, std::string_view contents, tr_erro
|
||||
return false;
|
||||
}
|
||||
|
||||
tr_logAddTrace("Saved \"%s\"", filename.c_str());
|
||||
tr_logAddTrace(fmt::format("Saved '{}'", filename));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1134,7 +1160,11 @@ bool tr_moveFile(char const* oldpath, char const* newpath, tr_error** error)
|
||||
|
||||
if (!tr_sys_path_remove(oldpath, &my_error))
|
||||
{
|
||||
tr_logAddError("Unable to remove file at old path: %s", my_error->message);
|
||||
tr_logAddError(fmt::format(
|
||||
_("Couldn't remove '{path}': {errmsg} ({errcode})"),
|
||||
fmt::arg("path", oldpath),
|
||||
fmt::arg("errmsg", my_error->message),
|
||||
fmt::arg("errcode", my_error->code)));
|
||||
tr_error_free(my_error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user