Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Charles Kerr <charles@charleskerr.com>
  • Loading branch information
piec and ckerr committed Mar 25, 2022
1 parent ec4893b commit cacf4fe
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions daemon/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,24 @@ static auto onFileAdded(tr_watchdir_t dir, char const* name, void* vsession)
retry = true;
}
}
else if (tr_str_has_suffix(name, ".magnet"))
else // ".magnet" suffix
{
auto content = std::vector<char>{};
if (!tr_loadFile(content, filename))
tr_error* error = nullptr;
if (!tr_loadFile(content, filename, &error))
{
tr_logAddInfo("cannot read file \"%s\"", name);
tr_logAddWarn(fmt::format(
_("Couldn't read '{path}': {error} ({error_code})"),
fmt::arg("path", handle->path),
fmt::arg("error", error->message),
fmt::arg("error_code", error->code)));
tr_error_free(error);
retry = true;
}
}
else
{
content.push_back(0); // string terminal 0
auto data = content.data();
content.push_back('\0'); // zero-terminated string
auto const* data = std::data(content);
if (!tr_ctorSetMetainfoFromMagnetLink(ctor, data, nullptr))
{
retry = true;
Expand All @@ -279,7 +285,7 @@ static auto onFileAdded(tr_watchdir_t dir, char const* name, void* vsession)
bool trash = false;
bool const test = tr_ctorGetDeleteSource(ctor, &trash);

if (test && trash)
if (test && trash)
{
tr_error* error = nullptr;

Expand Down

0 comments on commit cacf4fe

Please sign in to comment.