Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport file_renamed_alert::old_name() to RC_1_2 branch #7559

Open
wants to merge 1 commit into
base: RC_1_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/libtorrent/alert_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,22 @@ TORRENT_VERSION_NAMESPACE_2
{
// internal
file_renamed_alert(aux::stack_allocator& alloc, torrent_handle const& h
, string_view n, file_index_t idx);
, string_view n, string_view old, file_index_t idx);

TORRENT_DEFINE_ALERT_PRIO(file_renamed_alert, 7, alert_priority_critical)

static constexpr alert_category_t static_category = alert_category::storage;
std::string message() const override;

// returns the new and previous file name, respectively.
char const* new_name() const;
char const* old_name() const;

// refers to the index of the file that was renamed,
file_index_t const index;
private:
aux::allocation_slot m_name_idx;
aux::allocation_slot m_old_name_idx;
#if TORRENT_ABI_VERSION == 1

#if defined __clang__
Expand Down
11 changes: 10 additions & 1 deletion src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ namespace libtorrent {
: torrent_alert(alloc, h)
, index(idx)
, m_name_idx(alloc.copy_string(n))
, m_old_name_idx(alloc.copy_string(old))
#if TORRENT_ABI_VERSION == 1
, name(n)
#endif
Expand All @@ -258,17 +259,25 @@ namespace libtorrent {
return m_alloc.get().ptr(m_name_idx);
}

char const* file_renamed_alert::old_name() const
{
return m_alloc.get().ptr(m_old_name_idx);
}

std::string file_renamed_alert::message() const
{
#ifdef TORRENT_DISABLE_ALERT_MSG
return {};
#else
std::string ret { torrent_alert::message() };
char msg[200];
std::snprintf(msg, sizeof(msg), ": file %d renamed to "
std::snprintf(msg, sizeof(msg), ": file %d renamed from \""
, static_cast<int>(index));
ret.append(msg);
ret.append(old_name());
ret.append("\" to \"");
ret.append(new_name());
ret.append("\"");
return ret;
#endif
}
Expand Down
Loading