@@ -47,10 +47,8 @@ POSSIBILITY OF SUCH DAMAGE.
47
47
48
48
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
49
49
#define TORRENT_SEPARATOR ' \\ '
50
- #define TORRENT_SEPARATOR_STR " \\ "
51
50
#else
52
51
#define TORRENT_SEPARATOR ' /'
53
- #define TORRENT_SEPARATOR_STR " /"
54
52
#endif
55
53
56
54
namespace libtorrent
@@ -138,13 +136,14 @@ namespace libtorrent
138
136
return fe1.size < fe2.size ;
139
137
}
140
138
141
- bool compare_file_offset (internal_file_entry const & lhs
142
- , internal_file_entry const & rhs)
143
- {
144
- return lhs.offset < rhs.offset ;
145
- }
139
+ bool compare_file_offset (internal_file_entry const & lhs
140
+ , internal_file_entry const & rhs)
141
+ {
142
+ return lhs.offset < rhs.offset ;
146
143
}
147
144
145
+ }
146
+
148
147
// path is not supposed to include the name of the torrent itself.
149
148
void file_storage::update_path_index (internal_file_entry& e
150
149
, std::string const & path, bool set_name)
@@ -193,6 +192,16 @@ namespace libtorrent
193
192
e.no_root_dir = true ;
194
193
}
195
194
195
+ e.path_index = get_or_add_path (branch_path, branch_len);
196
+ if (set_name) e.set_name (leaf);
197
+ }
198
+
199
+ int file_storage::get_or_add_path (char const * branch_path, int branch_len)
200
+ {
201
+ // trim trailing slashes
202
+ if (branch_len > 0 && branch_path[branch_len-1 ] == TORRENT_SEPARATOR)
203
+ --branch_len;
204
+
196
205
// do we already have this path in the path list?
197
206
std::vector<std::string>::reverse_iterator p
198
207
= std::find_if (m_paths.rbegin (), m_paths.rend ()
@@ -201,23 +210,16 @@ namespace libtorrent
201
210
if (p == m_paths.rend ())
202
211
{
203
212
// no, we don't. add it
204
- e.path_index = m_paths.size ();
205
- TORRENT_ASSERT (branch_path[0 ] != ' /' );
206
-
207
- // trim trailing slashes
208
- if (branch_len > 0 && branch_path[branch_len-1 ] == TORRENT_SEPARATOR)
209
- --branch_len;
210
-
211
- // poor man's emplace back
212
- m_paths.resize (m_paths.size () + 1 );
213
- m_paths.back ().assign (branch_path, branch_len);
213
+ int const ret = int (m_paths.size ());
214
+ TORRENT_ASSERT (branch_len == 0 || branch_path[0 ] != TORRENT_SEPARATOR);
215
+ m_paths.push_back (std::string (branch_path, branch_len));
216
+ return ret;
214
217
}
215
218
else
216
219
{
217
220
// yes we do. use it
218
- e. path_index = p.base () - m_paths.begin () - 1 ;
221
+ return int ( p.base () - m_paths.begin () - 1 ) ;
219
222
}
220
- if (set_name) e.set_name (leaf);
221
223
}
222
224
223
225
#ifndef TORRENT_NO_DEPRECATE
@@ -396,6 +398,8 @@ namespace libtorrent
396
398
397
399
int file_storage::file_index_at_offset (boost::int64_t offset) const
398
400
{
401
+ TORRENT_ASSERT_PRECOND (offset >= 0 );
402
+ TORRENT_ASSERT_PRECOND (offset < m_total_size);
399
403
// find the file iterator and file offset
400
404
internal_file_entry target;
401
405
target.offset = offset;
@@ -425,6 +429,8 @@ namespace libtorrent
425
429
, boost::int64_t const offset
426
430
, int size) const
427
431
{
432
+ TORRENT_ASSERT_PRECOND (piece >= 0 );
433
+ TORRENT_ASSERT_PRECOND (piece < num_pieces ());
428
434
TORRENT_ASSERT_PRECOND (num_files () > 0 );
429
435
std::vector<file_slice> ret;
430
436
@@ -1067,11 +1073,10 @@ namespace libtorrent
1067
1073
i = m_files.begin () + cur_index;
1068
1074
e.size = size;
1069
1075
e.offset = offset;
1070
- char name[30 ];
1071
- snprintf (name, sizeof (name), " .pad" TORRENT_SEPARATOR_STR " %d"
1072
- , pad_file_counter);
1073
- std::string path = combine_path (m_name, name);
1074
- e.set_name (path.c_str ());
1076
+ e.path_index = get_or_add_path (" .pad" , 4 );
1077
+ char name[15 ];
1078
+ snprintf (name, sizeof (name), " %d" , pad_file_counter);
1079
+ e.set_name (name);
1075
1080
e.pad_file = true ;
1076
1081
offset += size;
1077
1082
++pad_file_counter;
0 commit comments