mirror of https://github.com/aria2/aria2
Throw exception when unrecognized URI, bad Metalink or bad .torrent
file are given in command-line and exits with status non-zero.pull/1/head
parent
c81dcd80ea
commit
c03ab007a3
|
@ -366,12 +366,16 @@ private:
|
||||||
ProtocolDetector detector_;
|
ProtocolDetector detector_;
|
||||||
SharedHandle<Option> option_;
|
SharedHandle<Option> option_;
|
||||||
bool ignoreLocalPath_;
|
bool ignoreLocalPath_;
|
||||||
|
bool throwOnError_;
|
||||||
public:
|
public:
|
||||||
AccRequestGroup(std::vector<SharedHandle<RequestGroup> >& requestGroups,
|
AccRequestGroup(std::vector<SharedHandle<RequestGroup> >& requestGroups,
|
||||||
const SharedHandle<Option>& option,
|
const SharedHandle<Option>& option,
|
||||||
bool ignoreLocalPath = false):
|
bool ignoreLocalPath = false,
|
||||||
|
bool throwOnError = false):
|
||||||
requestGroups_(requestGroups), option_(option),
|
requestGroups_(requestGroups), option_(option),
|
||||||
ignoreLocalPath_(ignoreLocalPath) {}
|
ignoreLocalPath_(ignoreLocalPath),
|
||||||
|
throwOnError_(throwOnError)
|
||||||
|
{}
|
||||||
|
|
||||||
void
|
void
|
||||||
operator()(const std::string& uri)
|
operator()(const std::string& uri)
|
||||||
|
@ -390,23 +394,21 @@ public:
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
else if(detector_.guessTorrentMagnet(uri)) {
|
else if(detector_.guessTorrentMagnet(uri)) {
|
||||||
try {
|
SharedHandle<RequestGroup> group =
|
||||||
SharedHandle<RequestGroup> group =
|
createBtMagnetRequestGroup(uri, option_);
|
||||||
createBtMagnetRequestGroup(uri, option_);
|
requestGroups_.push_back(group);
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else if(!ignoreLocalPath_ && detector_.guessTorrentFile(uri)) {
|
} else if(!ignoreLocalPath_ && detector_.guessTorrentFile(uri)) {
|
||||||
try {
|
try {
|
||||||
requestGroups_.push_back
|
requestGroups_.push_back
|
||||||
(createBtRequestGroup(uri, option_, std::vector<std::string>()));
|
(createBtRequestGroup(uri, option_, std::vector<std::string>()));
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
// error occurred while parsing torrent file.
|
if(throwOnError_) {
|
||||||
// We simply ignore it.
|
throw;
|
||||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
} else {
|
||||||
|
// error occurred while parsing torrent file.
|
||||||
|
// We simply ignore it.
|
||||||
|
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
@ -415,14 +417,22 @@ public:
|
||||||
try {
|
try {
|
||||||
Metalink2RequestGroup().generate(requestGroups_, uri, option_);
|
Metalink2RequestGroup().generate(requestGroups_, uri, option_);
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
// error occurred while parsing metalink file.
|
if(throwOnError_) {
|
||||||
// We simply ignore it.
|
throw;
|
||||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
} else {
|
||||||
|
// error occurred while parsing metalink file.
|
||||||
|
// We simply ignore it.
|
||||||
|
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
else {
|
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 SharedHandle<Option>& option,
|
||||||
const std::vector<std::string>& uris,
|
const std::vector<std::string>& uris,
|
||||||
bool ignoreForceSequential,
|
bool ignoreForceSequential,
|
||||||
bool ignoreLocalPath)
|
bool ignoreLocalPath,
|
||||||
|
bool throwOnError)
|
||||||
{
|
{
|
||||||
std::vector<std::string> nargs;
|
std::vector<std::string> nargs;
|
||||||
if(option->get(PREF_PARAMETERIZED_URI) == A2_V_TRUE) {
|
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) {
|
if(!ignoreForceSequential && option->get(PREF_FORCE_SEQUENTIAL) == A2_V_TRUE) {
|
||||||
std::for_each(nargs.begin(), nargs.end(),
|
std::for_each(nargs.begin(), nargs.end(),
|
||||||
AccRequestGroup(result, option, ignoreLocalPath));
|
AccRequestGroup(result, option, ignoreLocalPath,
|
||||||
|
throwOnError));
|
||||||
} else {
|
} else {
|
||||||
std::vector<std::string>::iterator strmProtoEnd =
|
std::vector<std::string>::iterator strmProtoEnd =
|
||||||
std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter());
|
std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter());
|
||||||
|
@ -471,7 +483,8 @@ void createRequestGroupForUri
|
||||||
}
|
}
|
||||||
// process remaining URIs(local metalink, BitTorrent files)
|
// process remaining URIs(local metalink, BitTorrent files)
|
||||||
std::for_each(strmProtoEnd, nargs.end(),
|
std::for_each(strmProtoEnd, nargs.end(),
|
||||||
AccRequestGroup(result, option, ignoreLocalPath));
|
AccRequestGroup(result, option, ignoreLocalPath,
|
||||||
|
throwOnError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,13 +87,18 @@ void createRequestGroupForUriList
|
||||||
const SharedHandle<Option>& option);
|
const SharedHandle<Option>& option);
|
||||||
|
|
||||||
// Create RequestGroup object using provided uris. If ignoreLocalPath
|
// 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
|
void createRequestGroupForUri
|
||||||
(std::vector<SharedHandle<RequestGroup> >& result,
|
(std::vector<SharedHandle<RequestGroup> >& result,
|
||||||
const SharedHandle<Option>& option,
|
const SharedHandle<Option>& option,
|
||||||
const std::vector<std::string>& uris,
|
const std::vector<std::string>& uris,
|
||||||
bool ignoreForceSequential = false,
|
bool ignoreForceSequential = false,
|
||||||
bool ignoreLocalPath = false);
|
bool ignoreLocalPath = false,
|
||||||
|
bool throwOnError = false);
|
||||||
|
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
void setMetadataInfo
|
void setMetadataInfo
|
||||||
|
|
|
@ -250,7 +250,7 @@ error_code::Value main(int argc, char* argv[])
|
||||||
return exitStatus;
|
return exitStatus;
|
||||||
#endif // ENABLE_METALINK || ENABLE_METALINK
|
#endif // ENABLE_METALINK || ENABLE_METALINK
|
||||||
} else {
|
} else {
|
||||||
createRequestGroupForUri(requestGroups, op, args);
|
createRequestGroupForUri(requestGroups, op, args, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove option values which is only valid for URIs specified in
|
// Remove option values which is only valid for URIs specified in
|
||||||
|
|
Loading…
Reference in New Issue