mirror of https://github.com/aria2/aria2
2010-01-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Treat --dir="" as --dir="." * src/FtpNegotiationCommand.cc * src/HttpResponseCommand.cc * src/Metalink2RequestGroup.cc * src/UTMetadataPostDownloadHandler.cc * src/bittorrent_helper.cc * src/download_helper.cc * src/util.cc * src/util.h * test/UtilTest.ccpull/1/head
parent
2b62660e49
commit
4c89170488
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2010-01-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Treat --dir="" as --dir="."
|
||||||
|
* src/FtpNegotiationCommand.cc
|
||||||
|
* src/HttpResponseCommand.cc
|
||||||
|
* src/Metalink2RequestGroup.cc
|
||||||
|
* src/UTMetadataPostDownloadHandler.cc
|
||||||
|
* src/bittorrent_helper.cc
|
||||||
|
* src/download_helper.cc
|
||||||
|
* src/util.cc
|
||||||
|
* src/util.h
|
||||||
|
* test/UtilTest.cc
|
||||||
|
|
||||||
2010-01-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-01-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Code clean up.
|
Code clean up.
|
||||||
|
|
|
@ -336,8 +336,8 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
||||||
_fileEntry->setLength(totalLength);
|
_fileEntry->setLength(totalLength);
|
||||||
if(_fileEntry->getPath().empty()) {
|
if(_fileEntry->getPath().empty()) {
|
||||||
_fileEntry->setPath
|
_fileEntry->setPath
|
||||||
(strconcat(getDownloadContext()->getDir(),
|
(util::applyDir
|
||||||
"/", util::urldecode(req->getFile())));
|
(getDownloadContext()->getDir(), util::urldecode(req->getFile())));
|
||||||
}
|
}
|
||||||
_requestGroup->preDownloadProcessing();
|
_requestGroup->preDownloadProcessing();
|
||||||
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
||||||
|
|
|
@ -131,8 +131,8 @@ bool HttpResponseCommand::executeInternal()
|
||||||
_fileEntry->setLength(totalLength);
|
_fileEntry->setLength(totalLength);
|
||||||
if(_fileEntry->getPath().empty()) {
|
if(_fileEntry->getPath().empty()) {
|
||||||
_fileEntry->setPath
|
_fileEntry->setPath
|
||||||
(strconcat(getDownloadContext()->getDir(),
|
(util::applyDir
|
||||||
"/", httpResponse->determinFilename()));
|
(getDownloadContext()->getDir(), httpResponse->determinFilename()));
|
||||||
}
|
}
|
||||||
_fileEntry->setContentType(httpResponse->getContentType());
|
_fileEntry->setContentType(httpResponse->getContentType());
|
||||||
_requestGroup->preDownloadProcessing();
|
_requestGroup->preDownloadProcessing();
|
||||||
|
|
|
@ -218,7 +218,7 @@ Metalink2RequestGroup::createRequestGroup
|
||||||
(new DownloadContext
|
(new DownloadContext
|
||||||
(pieceLength,
|
(pieceLength,
|
||||||
entry->getLength(),
|
entry->getLength(),
|
||||||
strconcat(option->get(PREF_DIR), "/", entry->file->getPath())));
|
util::applyDir(option->get(PREF_DIR), entry->file->getPath())));
|
||||||
dctx->setDir(option->get(PREF_DIR));
|
dctx->setDir(option->get(PREF_DIR));
|
||||||
dctx->getFirstFileEntry()->setUris(uris);
|
dctx->getFirstFileEntry()->setUris(uris);
|
||||||
if(option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL)) {
|
if(option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL)) {
|
||||||
|
|
|
@ -82,23 +82,22 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups
|
||||||
util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
||||||
std::string torrent = bittorrent::metadata2Torrent(metadata, attrs);
|
std::string torrent = bittorrent::metadata2Torrent(metadata, attrs);
|
||||||
|
|
||||||
std::deque<SharedHandle<RequestGroup> > newRgs;
|
|
||||||
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
|
||||||
std::deque<std::string>(), torrent);
|
|
||||||
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
|
||||||
groups.insert(groups.end(), newRgs.begin(), newRgs.end());
|
|
||||||
|
|
||||||
if(requestGroup->getOption()->getAsBool(PREF_BT_SAVE_METADATA)) {
|
if(requestGroup->getOption()->getAsBool(PREF_BT_SAVE_METADATA)) {
|
||||||
std::string filename = requestGroup->getOption()->get(PREF_DIR);
|
std::string filename =
|
||||||
filename += A2STR::SLASH_C;
|
util::applyDir(requestGroup->getOption()->get(PREF_DIR),
|
||||||
filename += util::toHex(attrs[bittorrent::INFO_HASH].s());
|
util::toHex(attrs[bittorrent::INFO_HASH].s())+".torrent");
|
||||||
filename += ".torrent";
|
|
||||||
if(util::saveAs(filename, torrent)) {
|
if(util::saveAs(filename, torrent)) {
|
||||||
_logger->notice(MSG_METADATA_SAVED, filename.c_str());
|
_logger->notice(MSG_METADATA_SAVED, filename.c_str());
|
||||||
} else {
|
} else {
|
||||||
_logger->notice(MSG_METADATA_NOT_SAVED, filename.c_str());
|
_logger->notice(MSG_METADATA_NOT_SAVED, filename.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::deque<SharedHandle<RequestGroup> > newRgs;
|
||||||
|
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
||||||
|
std::deque<std::string>(), torrent);
|
||||||
|
|
||||||
|
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
||||||
|
groups.insert(groups.end(), newRgs.begin(), newRgs.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -260,7 +260,7 @@ static void extractFileEntries
|
||||||
std::deque<std::string> uris;
|
std::deque<std::string> uris;
|
||||||
createUri(urlList.begin(), urlList.end(), std::back_inserter(uris), path);
|
createUri(urlList.begin(), urlList.end(), std::back_inserter(uris), path);
|
||||||
SharedHandle<FileEntry> fileEntry
|
SharedHandle<FileEntry> fileEntry
|
||||||
(new FileEntry(strconcat(ctx->getDir(), "/", path),
|
(new FileEntry(util::applyDir(ctx->getDir(), path),
|
||||||
fileLengthData.i(),
|
fileLengthData.i(),
|
||||||
offset, uris));
|
offset, uris));
|
||||||
fileEntries.push_back(fileEntry);
|
fileEntries.push_back(fileEntry);
|
||||||
|
@ -289,13 +289,13 @@ static void extractFileEntries
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle<FileEntry> fileEntry
|
SharedHandle<FileEntry> fileEntry
|
||||||
(new FileEntry(strconcat(ctx->getDir(), "/", name),totalLength, 0,
|
(new FileEntry(util::applyDir(ctx->getDir(), name),totalLength, 0,
|
||||||
uris));
|
uris));
|
||||||
fileEntries.push_back(fileEntry);
|
fileEntries.push_back(fileEntry);
|
||||||
}
|
}
|
||||||
ctx->setFileEntries(fileEntries.begin(), fileEntries.end());
|
ctx->setFileEntries(fileEntries.begin(), fileEntries.end());
|
||||||
if(torrent[MODE].s() == MULTI) {
|
if(torrent[MODE].s() == MULTI) {
|
||||||
ctx->setBasePath(strconcat(ctx->getDir(), "/", name));
|
ctx->setBasePath(util::applyDir(ctx->getDir(), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ static SharedHandle<RequestGroup> createRequestGroup
|
||||||
(option->getAsInt(PREF_SEGMENT_SIZE),
|
(option->getAsInt(PREF_SEGMENT_SIZE),
|
||||||
0,
|
0,
|
||||||
useOutOption&&!option->blank(PREF_OUT)?
|
useOutOption&&!option->blank(PREF_OUT)?
|
||||||
strconcat(option->get(PREF_DIR), "/", option->get(PREF_OUT)):A2STR::NIL));
|
util::applyDir(option->get(PREF_DIR), option->get(PREF_OUT)):A2STR::NIL));
|
||||||
dctx->setDir(option->get(PREF_DIR));
|
dctx->setDir(option->get(PREF_DIR));
|
||||||
dctx->getFirstFileEntry()->setUris(uris);
|
dctx->getFirstFileEntry()->setUris(uris);
|
||||||
rg->setDownloadContext(dctx);
|
rg->setDownloadContext(dctx);
|
||||||
|
@ -223,7 +223,7 @@ createBtRequestGroup(const std::string& torrentFilePath,
|
||||||
for(std::map<size_t, std::string>::const_iterator i = indexPathMap.begin();
|
for(std::map<size_t, std::string>::const_iterator i = indexPathMap.begin();
|
||||||
i != indexPathMap.end(); ++i) {
|
i != indexPathMap.end(); ++i) {
|
||||||
dctx->setFilePathWithIndex
|
dctx->setFilePathWithIndex
|
||||||
((*i).first, strconcat(dctx->getDir(), "/", (*i).second));
|
((*i).first, util::applyDir(dctx->getDir(), (*i).second));
|
||||||
}
|
}
|
||||||
rg->setDownloadContext(dctx);
|
rg->setDownloadContext(dctx);
|
||||||
return rg;
|
return rg;
|
||||||
|
|
11
src/util.cc
11
src/util.cc
|
@ -1000,6 +1000,17 @@ bool saveAs
|
||||||
return File(tempFilename).renameTo(filename);
|
return File(tempFilename).renameTo(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string applyDir(const std::string& dir, const std::string& relPath)
|
||||||
|
{
|
||||||
|
if(dir.empty()) {
|
||||||
|
return strconcat(A2STR::DOT_C, A2STR::SLASH_C, relPath);
|
||||||
|
} else if(dir == A2STR::SLASH_C) {
|
||||||
|
return strconcat(A2STR::SLASH_C, relPath);
|
||||||
|
} else {
|
||||||
|
return strconcat(dir, A2STR::SLASH_C, relPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -355,6 +355,13 @@ void generateRandomData(unsigned char* data, size_t length);
|
||||||
bool saveAs
|
bool saveAs
|
||||||
(const std::string& filename, const std::string& data, bool overwrite=false);
|
(const std::string& filename, const std::string& data, bool overwrite=false);
|
||||||
|
|
||||||
|
// Prepend dir to relPath. If dir is empty, it prepends "." to relPath.
|
||||||
|
//
|
||||||
|
// dir = "/dir", relPath = "foo" => "/dir/foo"
|
||||||
|
// dir = "", relPath = "foo" => "./foo"
|
||||||
|
// dir = "/", relPath = "foo" => "/foo"
|
||||||
|
std::string applyDir(const std::string& dir, const std::string& relPath);
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -58,6 +58,7 @@ class UtilTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testGenerateRandomData);
|
CPPUNIT_TEST(testGenerateRandomData);
|
||||||
CPPUNIT_TEST(testFromHex);
|
CPPUNIT_TEST(testFromHex);
|
||||||
CPPUNIT_TEST(testParsePrioritizePieceRange);
|
CPPUNIT_TEST(testParsePrioritizePieceRange);
|
||||||
|
CPPUNIT_TEST(testApplyDir);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -104,6 +105,7 @@ public:
|
||||||
void testGenerateRandomData();
|
void testGenerateRandomData();
|
||||||
void testFromHex();
|
void testFromHex();
|
||||||
void testParsePrioritizePieceRange();
|
void testParsePrioritizePieceRange();
|
||||||
|
void testApplyDir();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -900,4 +902,12 @@ void UtilTest::testParsePrioritizePieceRange()
|
||||||
CPPUNIT_ASSERT(result.empty());
|
CPPUNIT_ASSERT(result.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UtilTest::testApplyDir()
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("./pred"), util::applyDir("", "pred"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("/pred"), util::applyDir("/", "pred"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("./pred"), util::applyDir(".", "pred"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("/dl/pred"), util::applyDir("/dl", "pred"));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue