summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-12-04 17:19:31 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-12-04 17:19:31 +0900
commitc03ab007a3adb1718a56fc2db2dcf5aa0975091f (patch)
treeb72611682a039a8f8053375fef4e8aa4d46ddb2d /src
parentc81dcd80ea1ea7d093039a14d82a81142ae2554d (diff)
Throw exception when unrecognized URI, bad Metalink or bad .torrent
file are given in command-line and exits with status non-zero.
Diffstat (limited to 'src')
-rw-r--r--src/download_helper.cc55
-rw-r--r--src/download_helper.h9
-rw-r--r--src/main.cc2
3 files changed, 42 insertions, 24 deletions
diff --git a/src/download_helper.cc b/src/download_helper.cc
index d3a7af3b..204a5bb8 100644
--- a/src/download_helper.cc
+++ b/src/download_helper.cc
@@ -366,12 +366,16 @@ private:
ProtocolDetector detector_;
SharedHandle<Option> option_;
bool ignoreLocalPath_;
+ bool throwOnError_;
public:
AccRequestGroup(std::vector<SharedHandle<RequestGroup> >& requestGroups,
const SharedHandle<Option>& option,
- bool ignoreLocalPath = false):
+ bool ignoreLocalPath = false,
+ bool throwOnError = false):
requestGroups_(requestGroups), option_(option),
- ignoreLocalPath_(ignoreLocalPath) {}
+ ignoreLocalPath_(ignoreLocalPath),
+ throwOnError_(throwOnError)
+ {}
void
operator()(const std::string& uri)
@@ -390,23 +394,21 @@ public:
}
#ifdef ENABLE_BITTORRENT
else if(detector_.guessTorrentMagnet(uri)) {
- try {
- SharedHandle<RequestGroup> group =
- createBtMagnetRequestGroup(uri, option_);
- requestGroups_.push_back(group);
- } catch(RecoverableException& e) {
- // error occurred while parsing torrent file.
- // We simply ignore it.
- A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
- }
+ SharedHandle<RequestGroup> group =
+ createBtMagnetRequestGroup(uri, option_);
+ requestGroups_.push_back(group);
} else if(!ignoreLocalPath_ && detector_.guessTorrentFile(uri)) {
try {
requestGroups_.push_back
(createBtRequestGroup(uri, option_, std::vector<std::string>()));
} catch(RecoverableException& e) {
- // error occurred while parsing torrent file.
- // We simply ignore it.
- A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
+ if(throwOnError_) {
+ throw;
+ } else {
+ // error occurred while parsing torrent file.
+ // We simply ignore it.
+ A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
+ }
}
}
#endif // ENABLE_BITTORRENT
@@ -415,14 +417,22 @@ public:
try {
Metalink2RequestGroup().generate(requestGroups_, uri, option_);
} catch(RecoverableException& e) {
- // error occurred while parsing metalink file.
- // We simply ignore it.
- A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
+ if(throwOnError_) {
+ throw;
+ } else {
+ // error occurred while parsing metalink file.
+ // We simply ignore it.
+ A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
+ }
}
}
#endif // ENABLE_METALINK
else {
- A2_LOG_ERROR(fmt(MSG_UNRECOGNIZED_URI, (uri).c_str()));
+ if(throwOnError_) {
+ throw DL_ABORT_EX(fmt(MSG_UNRECOGNIZED_URI, uri.c_str()));
+ } else {
+ A2_LOG_ERROR(fmt(MSG_UNRECOGNIZED_URI, uri.c_str()));
+ }
}
}
};
@@ -444,7 +454,8 @@ void createRequestGroupForUri
const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
bool ignoreForceSequential,
- bool ignoreLocalPath)
+ bool ignoreLocalPath,
+ bool throwOnError)
{
std::vector<std::string> nargs;
if(option->get(PREF_PARAMETERIZED_URI) == A2_V_TRUE) {
@@ -454,7 +465,8 @@ void createRequestGroupForUri
}
if(!ignoreForceSequential && option->get(PREF_FORCE_SEQUENTIAL) == A2_V_TRUE) {
std::for_each(nargs.begin(), nargs.end(),
- AccRequestGroup(result, option, ignoreLocalPath));
+ AccRequestGroup(result, option, ignoreLocalPath,
+ throwOnError));
} else {
std::vector<std::string>::iterator strmProtoEnd =
std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter());
@@ -471,7 +483,8 @@ void createRequestGroupForUri
}
// process remaining URIs(local metalink, BitTorrent files)
std::for_each(strmProtoEnd, nargs.end(),
- AccRequestGroup(result, option, ignoreLocalPath));
+ AccRequestGroup(result, option, ignoreLocalPath,
+ throwOnError));
}
}
diff --git a/src/download_helper.h b/src/download_helper.h
index 47df07cd..6bd0b7f0 100644
--- a/src/download_helper.h
+++ b/src/download_helper.h
@@ -87,13 +87,18 @@ void createRequestGroupForUriList
const SharedHandle<Option>& option);
// Create RequestGroup object using provided uris. If ignoreLocalPath
-// is true, a path to torrent file abd metalink file are ignored.
+// is true, a path to torrent file abd metalink file are ignored. If
+// throwOnError is true, exception will be thrown when Metalink
+// Document or .torrent file cannot be parsed or unrecognized URI is
+// given. If throwOnError is false, these errors are just logged as
+// error.
void createRequestGroupForUri
(std::vector<SharedHandle<RequestGroup> >& result,
const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
bool ignoreForceSequential = false,
- bool ignoreLocalPath = false);
+ bool ignoreLocalPath = false,
+ bool throwOnError = false);
template<typename InputIterator>
void setMetadataInfo
diff --git a/src/main.cc b/src/main.cc
index 6cc47c86..f44ceda8 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -250,7 +250,7 @@ error_code::Value main(int argc, char* argv[])
return exitStatus;
#endif // ENABLE_METALINK || ENABLE_METALINK
} else {
- createRequestGroupForUri(requestGroups, op, args);
+ createRequestGroupForUri(requestGroups, op, args, false, false, true);
}
// Remove option values which is only valid for URIs specified in