2009-03-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Prepended _dir+"/" after joining path elements in torrent file.
	* src/DefaultBtContext.cc
	* test/DefaultBtContextTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-03-13 16:10:28 +00:00
parent 49fea7585b
commit 75a525b031
3 changed files with 48 additions and 12 deletions

View File

@ -1,3 +1,9 @@
2009-03-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Prepended _dir+"/" after joining path elements in torrent file.
* src/DefaultBtContext.cc
* test/DefaultBtContextTest.cc
2009-03-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added missing IndexBtMessageValidator.h

View File

@ -154,19 +154,18 @@ void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
std::vector<std::string> pathelem(pathList.size());
std::transform(pathList.listBegin(), pathList.listEnd(), pathelem.begin(),
std::mem_fun_ref(&bencode::BDE::s));
std::string path = Util::joinPath(pathelem.begin(), pathelem.end());
std::string path =
name+"/"+Util::joinPath(pathelem.begin(), pathelem.end());
// Split path with '/' again because each pathList element can
// contain "/" inside.
std::deque<std::string> elements;
Util::slice(elements, path, '/');
elements.push_front(name);
elements.push_front(_dir);
path = Util::joinPath(elements.begin(), elements.end());
std::deque<std::string> uris;
std::transform(urlList.begin(), urlList.end(), std::back_inserter(uris),
std::bind2nd(std::plus<std::string>(), "/"+path));
FileEntryHandle fileEntry(new FileEntry(path, fileLengthData.i(),
FileEntryHandle fileEntry(new FileEntry(_dir+"/"+path, fileLengthData.i(),
offset, uris));
fileEntries.push_back(fileEntry);
offset += fileEntry->getLength();
@ -184,9 +183,8 @@ void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
// Slice path by '/' just in case nasty ".." is included in name
std::deque<std::string> pathelems;
Util::slice(pathelems, name, '/');
pathelems.push_front(_dir);
SharedHandle<FileEntry> fileEntry
(new FileEntry(Util::joinPath(pathelems.begin(), pathelems.end()),
(new FileEntry(_dir+"/"+Util::joinPath(pathelems.begin(),pathelems.end()),
totalLength, 0, urlList));
fileEntries.push_back(fileEntry);
}

View File

@ -39,6 +39,8 @@ class DefaultBtContextTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testLoadFromMemory);
CPPUNIT_TEST(testLoadFromMemory_somethingMissing);
CPPUNIT_TEST(testLoadFromMemory_overrideName);
CPPUNIT_TEST(testLoadFromMemory_joinPathMulti);
CPPUNIT_TEST(testLoadFromMemory_joinPathSingle);
CPPUNIT_TEST(testGetNodes);
CPPUNIT_TEST_SUITE_END();
public:
@ -67,6 +69,8 @@ public:
void testLoadFromMemory();
void testLoadFromMemory_somethingMissing();
void testLoadFromMemory_overrideName();
void testLoadFromMemory_joinPathMulti();
void testLoadFromMemory_joinPathSingle();
void testGetNodes();
};
@ -108,11 +112,11 @@ void DefaultBtContextTest::testGetFileEntries() {
std::deque<SharedHandle<FileEntry> >::iterator itr = fileEntries.begin();
SharedHandle<FileEntry> fileEntry1 = *itr;
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test/aria2/src/aria2c"),
CPPUNIT_ASSERT_EQUAL(std::string("./aria2-test/aria2/src/aria2c"),
fileEntry1->getPath());
itr++;
SharedHandle<FileEntry> fileEntry2 = *itr;
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test/aria2-0.2.2.tar.bz2"),
CPPUNIT_ASSERT_EQUAL(std::string("./aria2-test/aria2-0.2.2.tar.bz2"),
fileEntry2->getPath());
}
@ -126,7 +130,7 @@ void DefaultBtContextTest::testGetFileEntriesSingle() {
std::deque<SharedHandle<FileEntry> >::iterator itr = fileEntries.begin();
SharedHandle<FileEntry> fileEntry1 = *itr;
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.8.2.tar.bz2"),
CPPUNIT_ASSERT_EQUAL(std::string("./aria2-0.8.2.tar.bz2"),
fileEntry1->getPath());
}
@ -289,7 +293,7 @@ void DefaultBtContextTest::testGetFileEntries_multiFileUrlList() {
std::deque<SharedHandle<FileEntry> >::iterator itr = fileEntries.begin();
SharedHandle<FileEntry> fileEntry1 = *itr;
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test/aria2/src/aria2c"),
CPPUNIT_ASSERT_EQUAL(std::string("./aria2-test/aria2/src/aria2c"),
fileEntry1->getPath());
std::deque<std::string> uris1 = fileEntry1->getAssociatedUris();
CPPUNIT_ASSERT_EQUAL((size_t)2, uris1.size());
@ -300,7 +304,7 @@ void DefaultBtContextTest::testGetFileEntries_multiFileUrlList() {
itr++;
SharedHandle<FileEntry> fileEntry2 = *itr;
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test/aria2-0.2.2.tar.bz2"),
CPPUNIT_ASSERT_EQUAL(std::string("./aria2-test/aria2-0.2.2.tar.bz2"),
fileEntry2->getPath());
std::deque<std::string> uris2 = fileEntry2->getAssociatedUris();
CPPUNIT_ASSERT_EQUAL((size_t)2, uris2.size());
@ -319,7 +323,7 @@ void DefaultBtContextTest::testGetFileEntries_singleFileUrlList() {
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntries.size());
SharedHandle<FileEntry> fileEntry1 = fileEntries.front();
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"),
CPPUNIT_ASSERT_EQUAL(std::string("./aria2.tar.bz2"),
fileEntry1->getPath());
std::deque<std::string> uris1 = fileEntry1->getAssociatedUris();
CPPUNIT_ASSERT_EQUAL((size_t)1, uris1.size());
@ -364,6 +368,34 @@ void DefaultBtContextTest::testLoadFromMemory_overrideName()
CPPUNIT_ASSERT_EQUAL(std::string("aria2-override.name"), btContext.getName());
}
void DefaultBtContextTest::testLoadFromMemory_joinPathMulti()
{
std::string memory =
"d8:announce27:http://example.com/announce4:infod5:filesld6:lengthi262144e4:pathl7:../dir14:dir28:file.imgeee4:name14:../name1/name212:piece lengthi262144e6:pieces20:00000000000000000000ee";
DefaultBtContext btContext;
btContext.setDir("/tmp");
btContext.loadFromMemory(memory, "default");
CPPUNIT_ASSERT_EQUAL(std::string("../name1/name2"), btContext.getName());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/name1/dir1/dir2/file.img"),
btContext.getFileEntries().front()->getPath());
}
void DefaultBtContextTest::testLoadFromMemory_joinPathSingle()
{
std::string memory =
"d8:announce27:http://example.com/announce4:infod4:name14:../name1/name26:lengthi262144e12:piece lengthi262144e6:pieces20:00000000000000000000ee";
DefaultBtContext btContext;
btContext.setDir("/tmp");
btContext.loadFromMemory(memory, "default");
CPPUNIT_ASSERT_EQUAL(std::string("../name1/name2"), btContext.getName());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/name1/name2"),
btContext.getFileEntries().front()->getPath());
}
void DefaultBtContextTest::testGetNodes()
{
{