Skip to content

Commit 0fe2e85

Browse files
committed
fix part-file creation race condition (back-port from master)
1 parent 163e490 commit 0fe2e85

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
* fix part-file creation race condition
23
* fix issue with initializing settings on session construction
34
* fix issue with receiving interested before metadata
45
* fix IPv6 tracker announce issue

src/storage.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ namespace libtorrent
245245
if (file_index < int(m_storage.m_file_priority.size())
246246
&& m_storage.m_file_priority[file_index] == 0)
247247
{
248-
m_storage.need_partfile();
248+
TORRENT_ASSERT(m_storage.m_part_file);
249249

250250
error_code e;
251251
peer_request map = m_storage.files().map_file(file_index
@@ -335,7 +335,7 @@ namespace libtorrent
335335
if (file_index < int(m_storage.m_file_priority.size())
336336
&& m_storage.m_file_priority[file_index] == 0)
337337
{
338-
m_storage.need_partfile();
338+
TORRENT_ASSERT(m_storage.m_part_file);
339339

340340
error_code e;
341341
peer_request map = m_storage.files().map_file(file_index
@@ -412,6 +412,16 @@ namespace libtorrent
412412
m_part_file_name = "." + (params.info
413413
? to_hex(params.info->info_hash().to_string())
414414
: params.files->name()) + ".parts";
415+
416+
file_storage const& fs = files();
417+
for (int i = 0; i < m_file_priority.size(); ++i)
418+
{
419+
if (m_file_priority[i] == 0 && !fs.pad_file_at(i))
420+
{
421+
need_partfile();
422+
break;
423+
}
424+
}
415425
}
416426

417427
default_storage::~default_storage()
@@ -498,6 +508,9 @@ namespace libtorrent
498508
}
499509
ec.ec.clear();
500510
m_file_priority[i] = new_prio;
511+
512+
if (m_file_priority[i] == 0 && !fs.pad_file_at(i))
513+
need_partfile();
501514
}
502515
if (m_part_file) m_part_file->flush_metadata(ec.ec);
503516
if (ec)
@@ -747,7 +760,6 @@ namespace libtorrent
747760
{
748761
error_code ignore;
749762
m_part_file->flush_metadata(ignore);
750-
m_part_file.reset();
751763
}
752764

753765
// make sure we don't have the files open

test/test_priority.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void test_transfer(settings_pack const& sett)
123123
file.close();
124124

125125
wait_for_listen(ses1, "ses1");
126-
wait_for_listen(ses2, "ses1");
126+
wait_for_listen(ses2, "ses2");
127127

128128
peer_disconnects = 0;
129129

0 commit comments

Comments
 (0)