summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-12-03 13:08:22 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-12-03 13:08:22 +0900
commit0a2b1660fa282da899cba35f7105b9d424f915ca (patch)
tree5283e683278fac7660204bf3619ff6dc53a2183d /src
parent479f71efaffb8cbed3c4c22ad6e7b02869e8784f (diff)
Removed DownloadContext::dir_. Use PREF_DIR value instead.
Diffstat (limited to 'src')
-rw-r--r--src/BtDependency.cc7
-rw-r--r--src/DownloadContext.cc7
-rw-r--r--src/DownloadContext.h6
-rw-r--r--src/FtpNegotiationCommand.cc2
-rw-r--r--src/HttpRequestCommand.cc2
-rw-r--r--src/HttpResponseCommand.cc2
-rw-r--r--src/Metalink2RequestGroup.cc1
-rw-r--r--src/RequestGroup.cc2
-rw-r--r--src/TrackerWatcherCommand.cc1
-rw-r--r--src/XmlRpcMethodImpl.cc2
-rw-r--r--src/bittorrent_helper.cc24
-rw-r--r--src/bittorrent_helper.h6
-rw-r--r--src/download_helper.cc13
-rw-r--r--src/main.cc3
14 files changed, 42 insertions, 36 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<DownloadContext> context(new DownloadContext());
- context->setDir(dependant_->getDownloadContext()->getDir());
try {
SharedHandle<DiskAdaptor> diskAdaptor =
dependee->getPieceStorage()->getDiskAdaptor();
@@ -91,12 +90,14 @@ bool BtDependency::resolve()
SharedHandle<TorrentAttribute> 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_ = 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<SharedHandle<FileEntry> > fileEntries_;
- std::string dir_;
-
std::vector<std::string> 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<Signature>& getSignature() const { return signature_; }
void setSignature(const SharedHandle<Signature>& 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<DiskWriterFactory> 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<DownloadContext>& ctx,
const SharedHandle<TorrentAttribute>& torrent,
const Dict* infoDict,
+ const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName,
const std::vector<std::string>& urlList)
@@ -284,7 +285,8 @@ void extractFileEntries
std::vector<std::string> uris;
createUri(urlList.begin(), urlList.end(),std::back_inserter(uris),pePath);
SharedHandle<FileEntry> fileEntry
- (new FileEntry(util::applyDir(ctx->getDir(),util::escapePath(utf8Path)),
+ (new FileEntry(util::applyDir(option->get(PREF_DIR),
+ util::escapePath(utf8Path)),
fileLengthData->i(), offset, uris));
fileEntry->setOriginalName(path);
fileEntries.push_back(fileEntry);
@@ -312,14 +314,15 @@ void extractFileEntries
}
}
SharedHandle<FileEntry> fileEntry
- (new FileEntry(util::applyDir(ctx->getDir(), util::escapePath(utf8Name)),
+ (new FileEntry(util::applyDir(option->get(PREF_DIR),
+ util::escapePath(utf8Name)),
totalLength, 0, uris));
fileEntry->setOriginalName(name);
fileEntries.push_back(fileEntry);
}
ctx->setFileEntries(fileEntries.begin(), fileEntries.end());
if(torrent->mode == MULTI) {
- ctx->setBasePath(util::applyDir(ctx->getDir(), utf8Name));
+ ctx->setBasePath(util::applyDir(option->get(PREF_DIR), utf8Name));
}
}
} // namespace
@@ -392,6 +395,7 @@ namespace {
void processRootDictionary
(const SharedHandle<DownloadContext>& ctx,
const SharedHandle<ValueBase>& root,
+ const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName,
const std::vector<std::string>& uris)
@@ -466,7 +470,7 @@ void processRootDictionary
// retrieve file entries
extractFileEntries
- (ctx, torrent, infoDict, defaultName, overrideName, urlList);
+ (ctx, torrent, infoDict, option, defaultName, overrideName, urlList);
if((ctx->getTotalLength()+pieceLength-1)/pieceLength != numPieces) {
throw DL_ABORT_EX2("Too few/many piece hash.",
error_code::BITTORRENT_PARSE_ERROR);
@@ -500,10 +504,12 @@ void processRootDictionary
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode2::decodeFromFile(torrentFile),
+ option,
torrentFile,
overrideName,
std::vector<std::string>());
@@ -511,11 +517,13 @@ void load(const std::string& torrentFile,
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode2::decodeFromFile(torrentFile),
+ option,
torrentFile,
overrideName,
uris);
@@ -524,11 +532,13 @@ void load(const std::string& torrentFile,
void loadFromMemory(const unsigned char* content,
size_t length,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode2::decode(content, length),
+ option,
defaultName,
overrideName,
std::vector<std::string>());
@@ -537,12 +547,14 @@ void loadFromMemory(const unsigned char* content,
void loadFromMemory(const unsigned char* content,
size_t length,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode2::decode(content, length),
+ option,
defaultName,
overrideName,
uris);
@@ -550,18 +562,21 @@ void loadFromMemory(const unsigned char* content,
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName)
{
processRootDictionary
(ctx,
bencode2::decode(context),
+ option,
defaultName, overrideName,
std::vector<std::string>());
}
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
@@ -569,6 +584,7 @@ void loadFromMemory(const std::string& context,
processRootDictionary
(ctx,
bencode2::decode(context),
+ option,
defaultName, overrideName,
uris);
}
diff --git a/src/bittorrent_helper.h b/src/bittorrent_helper.h
index 3259bf7c..1dffe960 100644
--- a/src/bittorrent_helper.h
+++ b/src/bittorrent_helper.h
@@ -66,31 +66,37 @@ extern const std::string BITTORRENT;
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::string& overrideName = "");
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& overrideName = "");
void loadFromMemory(const unsigned char* content, size_t length,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const unsigned char* content, size_t length,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
+ const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName = "");
diff --git a/src/download_helper.cc b/src/download_helper.cc
index 1e3b67f6..04e04dcd 100644
--- a/src/download_helper.cc
+++ b/src/download_helper.cc
@@ -222,7 +222,6 @@ SharedHandle<RequestGroup> createRequestGroup
0,
useOutOption&&!option->blank(PREF_OUT)?
util::applyDir(option->get(PREF_DIR), option->get(PREF_OUT)):A2STR::NIL));
- dctx->setDir(option->get(PREF_DIR));
dctx->getFirstFileEntry()->setUris(uris);
dctx->getFirstFileEntry()->setMaxConnectionPerServer
(option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER));
@@ -259,14 +258,13 @@ createBtRequestGroup(const std::string& torrentFilePath,
{
SharedHandle<RequestGroup> rg(new RequestGroup(option));
SharedHandle<DownloadContext> dctx(new DownloadContext());
- dctx->setDir(option->get(PREF_DIR));
if(torrentData.empty()) {
- bittorrent::load(torrentFilePath, dctx, auxUris);// may throw exception
+ // may throw exception
+ bittorrent::load(torrentFilePath, dctx, option, auxUris);
rg->setMetadataInfo(createMetadataInfo(torrentFilePath));
} else {
- bittorrent::loadFromMemory(torrentData, dctx, auxUris, "default"); // may
- // throw
- // exception
+ // may throw exception
+ bittorrent::loadFromMemory(torrentData, dctx, option, auxUris, "default");
rg->setMetadataInfo(createMetadataInfoDataOnly());
}
if(adjustAnnounceUri) {
@@ -279,7 +277,7 @@ createBtRequestGroup(const std::string& torrentFilePath,
for(std::map<size_t, std::string>::const_iterator i = indexPathMap.begin(),
eoi = indexPathMap.end(); i != eoi; ++i) {
dctx->setFilePathWithIndex
- ((*i).first, util::applyDir(dctx->getDir(), (*i).second));
+ ((*i).first, util::applyDir(option->get(PREF_DIR), (*i).second));
}
rg->setDownloadContext(dctx);
// Remove "metalink" from Accept Type list to avoid server from
@@ -299,7 +297,6 @@ createBtMagnetRequestGroup(const std::string& magnetLink,
SharedHandle<DownloadContext> dctx
(new DownloadContext(METADATA_PIECE_SIZE, 0,
A2STR::NIL));
- dctx->setDir(A2STR::NIL);
// We only know info hash. Total Length is unknown at this moment.
dctx->markTotalLengthIsUnknown();
rg->setFileAllocationEnabled(false);
diff --git a/src/main.cc b/src/main.cc
index 5464867d..6cc47c86 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -113,8 +113,9 @@ std::ostream& getSummaryOut(const SharedHandle<Option>& op)
namespace {
void showTorrentFile(const std::string& uri)
{
+ SharedHandle<Option> op(new Option());
SharedHandle<DownloadContext> dctx(new DownloadContext());
- bittorrent::load(uri, dctx);
+ bittorrent::load(uri, dctx, op);
bittorrent::print(std::cout, dctx);
}
} // namespace