libtorrent code problem with const

I'm having a problem compiling some libtorrent code. Here is the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
libtorrent::torrent_handle th = ...;

// torrent_handle::torrent_file() is defined as:
//
// shared_ptr<const torrent_info> torrent_file() const;
//
std::shared_ptr<const libtorrent::torrent_info> ti = th.torrent_file();

// torrent_info::files() is defined as:
//
// file_storage const& files() const{...};
//
libtorrent::file_storage fs = ti->files();

// file_storage::set_name() is defined as:
//
// void set_name(std::string const& n){...};
//
fs.set_name("...");

// THIS IS THE LINE THAT CAUSES THE PROBLEM:
// error C2662: 'libtorrent::torrent_info::remap_files' : cannot convert 'this'
// pointer from 'const libtorrent::torrent_info' to 'libtorrent::torrent_info &'
// Conversion loses qualifiers.
ti->remap_files(fs);


I know that the problem is that "ti" is a "const libtorrent::torrent_info" and that the problem is the "const", because if I do the following it compiles with no warnings or errors:

1
2
std::shared_ptr<libtorrent::torrent_info> ti2; // note no "const"
ti2->remap_files(fs);


But, of course, "ti2" is not the torrent_info I need to update.

I'm trying to do it this way because the documentation says that it is the right way to do it - in "https://libtorrent.org/reference-Core.html#orig_files()" it clearly states "If you want to rename the base name of the torrent (for a multi file torrent), you can copy the file_storage (see files() and orig_files() ), change the name, and then use remap_files()."

I feel that I'm somehow doing something dumb, but I don't have enough coding experience to figure it out.
Last edited on
it clearly states "If you want to rename the base name of the torrent (for a multi file torrent), you can copy the file_storage (see files() and orig_files() ), change the name, and then use remap_files()."
The documentation says this in the context of torrent_info::rename_file(), which is also a non-const member function.
I don't think you can do this. It doesn't make sense to be able to rename the files inside a torrent file, since the torrent file contains hashes to check integrity.
Topic archived. No new replies allowed.