From 0a2b1660fa282da899cba35f7105b9d424f915ca Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 3 Dec 2010 13:08:22 +0900 Subject: [PATCH] Removed DownloadContext::dir_. Use PREF_DIR value instead. --- src/BtDependency.cc | 7 +- src/DownloadContext.cc | 7 -- src/DownloadContext.h | 6 -- src/FtpNegotiationCommand.cc | 2 +- src/HttpRequestCommand.cc | 2 +- src/HttpResponseCommand.cc | 2 +- src/Metalink2RequestGroup.cc | 1 - src/RequestGroup.cc | 2 +- src/TrackerWatcherCommand.cc | 1 - src/XmlRpcMethodImpl.cc | 2 +- src/bittorrent_helper.cc | 24 +++++- src/bittorrent_helper.h | 6 ++ src/download_helper.cc | 13 ++-- src/main.cc | 3 +- test/BittorrentHelperTest.cc | 89 ++++++++++++----------- test/BtDependencyTest.cc | 4 +- test/DefaultBtMessageDispatcherTest.cc | 3 +- test/DefaultBtProgressInfoFileTest.cc | 1 - test/DefaultPieceStorageTest.cc | 46 ++++++------ test/DownloadContextTest.cc | 3 - test/DownloadHelperTest.cc | 9 --- test/Metalink2RequestGroupTest.cc | 3 - test/UTMetadataPostDownloadHandlerTest.cc | 1 - test/XmlRpcMethodTest.cc | 7 +- 24 files changed, 117 insertions(+), 127 deletions(-) diff --git a/src/BtDependency.cc b/src/BtDependency.cc index 0c9649b5..7a5f8569 100644 --- a/src/BtDependency.cc +++ b/src/BtDependency.cc @@ -81,7 +81,6 @@ bool BtDependency::resolve() // cut reference here dependee_.reset(); SharedHandle context(new DownloadContext()); - context->setDir(dependant_->getDownloadContext()->getDir()); try { SharedHandle diskAdaptor = dependee->getPieceStorage()->getDiskAdaptor(); @@ -91,12 +90,14 @@ bool BtDependency::resolve() SharedHandle attrs = bittorrent::getTorrentAttrs(dependee->getDownloadContext()); bittorrent::loadFromMemory - (bittorrent::metadata2Torrent(content, attrs), context, "default"); + (bittorrent::metadata2Torrent(content, attrs), context, + dependant_->getOption(), "default"); // We don't call bittorrent::adjustAnnounceUri() because it // has already been called with attrs. } else { bittorrent::loadFromMemory - (content, context, File(dependee->getFirstFilePath()).getBasename()); + (content, context, dependant_->getOption(), + File(dependee->getFirstFilePath()).getBasename()); bittorrent::adjustAnnounceUri(bittorrent::getTorrentAttrs(context), dependant_->getOption()); } diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc index 4ff5370c..57b00989 100644 --- a/src/DownloadContext.cc +++ b/src/DownloadContext.cc @@ -48,7 +48,6 @@ namespace aria2 { DownloadContext::DownloadContext(): - dir_(A2STR::DOT_C), pieceLength_(0), checksumVerified_(false), knowsTotalLength_(true), @@ -59,7 +58,6 @@ DownloadContext::DownloadContext(): DownloadContext::DownloadContext(size_t pieceLength, uint64_t totalLength, const std::string& path): - dir_(A2STR::DOT_C), pieceLength_(pieceLength), checksumVerified_(false), knowsTotalLength_(true), @@ -259,11 +257,6 @@ void DownloadContext::setBasePath(const std::string& basePath) basePath_ = basePath; } -void DownloadContext::setDir(const std::string& dir) -{ - dir_ = dir; -} - void DownloadContext::setSignature(const SharedHandle& signature) { signature_ = signature; diff --git a/src/DownloadContext.h b/src/DownloadContext.h index fc343214..ccbb3097 100644 --- a/src/DownloadContext.h +++ b/src/DownloadContext.h @@ -59,8 +59,6 @@ class DownloadContext private: std::vector > fileEntries_; - std::string dir_; - std::vector pieceHashes_; size_t pieceLength_; @@ -161,10 +159,6 @@ public: void setBasePath(const std::string& basePath); - const std::string& getDir() const { return dir_; } - - void setDir(const std::string& dir); - const SharedHandle& getSignature() const { return signature_; } void setSignature(const SharedHandle& signature); diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 626d2a75..7ad09340 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -367,7 +367,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength) if(getFileEntry()->getPath().empty()) { getFileEntry()->setPath (util::createSafePath - (getDownloadContext()->getDir(), + (getOption()->get(PREF_DIR), util::percentDecode(getRequest()->getFile()))); } getRequestGroup()->preDownloadProcessing(); diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index 8d9919dd..a16e7691 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -158,7 +158,7 @@ bool HttpRequestCommand::executeInternal() { if(getFileEntry()->getPath().empty()) { getFileEntry()->setPath (util::createSafePath - (getDownloadContext()->getDir(), + (getOption()->get(PREF_DIR), util::percentDecode(getRequest()->getFile()))); } File ctrlfile(getFileEntry()->getPath()+ diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index 952ed8c1..47cab4b1 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -207,7 +207,7 @@ bool HttpResponseCommand::executeInternal() if(getFileEntry()->getPath().empty()) { getFileEntry()->setPath (util::createSafePath - (getDownloadContext()->getDir(), httpResponse->determinFilename())); + (getOption()->get(PREF_DIR), httpResponse->determinFilename())); } getFileEntry()->setContentType(httpResponse->getContentType()); getRequestGroup()->preDownloadProcessing(); diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 1f610937..c020d7ac 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -309,7 +309,6 @@ Metalink2RequestGroup::createRequestGroup dctx->setFileEntries(fileEntries.begin(), fileEntries.end()); rg->setNumConcurrentCommand(option->getAsInt(PREF_METALINK_SERVERS)); } - dctx->setDir(option->get(PREF_DIR)); rg->setDownloadContext(dctx); // remove "metalink" from Accept Type list to avoid loop in // tranparent metalink diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index e2e92a68..caa56960 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -1189,7 +1189,7 @@ DownloadResultHandle RequestGroup::createDownloadResult() const #endif // ENABLE_BITTORRENT res->pieceLength = downloadContext_->getPieceLength(); res->numPieces = downloadContext_->getNumPieces(); - res->dir = downloadContext_->getDir(); + res->dir = option_->get(PREF_DIR); return res; } diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index 41f38cad..f9263008 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -238,7 +238,6 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri) (new DownloadContext(getOption()->getAsInt(PREF_SEGMENT_SIZE), 0, TRACKER_ANNOUNCE_FILE)); - dctx->setDir(A2STR::NIL); dctx->getFileEntries().front()->setUris(uris); rg->setDownloadContext(dctx); SharedHandle dwf(new ByteArrayDiskWriterFactory()); diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc index 27b94438..dfc2805f 100644 --- a/src/XmlRpcMethodImpl.cc +++ b/src/XmlRpcMethodImpl.cc @@ -611,7 +611,7 @@ void gatherProgressCommon entryDict->put(KEY_FILES, files); } if(requested_key(keys, KEY_DIR)) { - entryDict->put(KEY_DIR, dctx->getDir()); + entryDict->put(KEY_DIR, group->getOption()->get(PREF_DIR)); } } diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index 0ab21a1d..8495c013 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -193,6 +193,7 @@ void extractFileEntries (const SharedHandle& ctx, const SharedHandle& torrent, const Dict* infoDict, + const SharedHandle