|
@@ -105,6 +105,28 @@ void splitURI(std::vector<std::string>& result,
|
|
|
}
|
|
|
} // namespace
|
|
|
|
|
|
+namespace {
|
|
|
+SharedHandle<GroupId> getGID(const SharedHandle<Option>& option)
|
|
|
+{
|
|
|
+ SharedHandle<GroupId> gid;
|
|
|
+ if(option->defined(PREF_GID)) {
|
|
|
+ a2_gid_t n;
|
|
|
+ if(GroupId::toNumericId(n, option->get(PREF_GID).c_str()) != 0) {
|
|
|
+ throw DL_ABORT_EX(fmt("%s is invalid for GID.",
|
|
|
+ option->get(PREF_GID).c_str()));
|
|
|
+ }
|
|
|
+ gid = GroupId::import(n);
|
|
|
+ if(!gid) {
|
|
|
+ throw DL_ABORT_EX(fmt("GID %s is not unique.",
|
|
|
+ option->get(PREF_GID).c_str()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ gid = GroupId::create();
|
|
|
+ }
|
|
|
+ return gid;
|
|
|
+}
|
|
|
+} // namespace
|
|
|
+
|
|
|
namespace {
|
|
|
SharedHandle<RequestGroup> createRequestGroup
|
|
|
(const SharedHandle<Option>& optionTemplate,
|
|
@@ -112,7 +134,7 @@ SharedHandle<RequestGroup> createRequestGroup
|
|
|
bool useOutOption = false)
|
|
|
{
|
|
|
SharedHandle<Option> option = util::copy(optionTemplate);
|
|
|
- SharedHandle<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
|
|
|
+ SharedHandle<RequestGroup> rg(new RequestGroup(getGID(option), option));
|
|
|
SharedHandle<DownloadContext> dctx
|
|
|
(new DownloadContext
|
|
|
(option->getAsInt(PREF_PIECE_LENGTH),
|
|
@@ -168,7 +190,7 @@ createBtRequestGroup(const std::string& metaInfoUri,
|
|
|
bool adjustAnnounceUri = true)
|
|
|
{
|
|
|
SharedHandle<Option> option = util::copy(optionTemplate);
|
|
|
- SharedHandle<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
|
|
|
+ SharedHandle<RequestGroup> rg(new RequestGroup(getGID(option), option));
|
|
|
SharedHandle<DownloadContext> dctx(new DownloadContext());
|
|
|
// may throw exception
|
|
|
bittorrent::loadFromMemory(torrent, dctx, option, auxUris,
|
|
@@ -210,7 +232,7 @@ createBtMagnetRequestGroup
|
|
|
const SharedHandle<Option>& optionTemplate)
|
|
|
{
|
|
|
SharedHandle<Option> option = util::copy(optionTemplate);
|
|
|
- SharedHandle<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
|
|
|
+ SharedHandle<RequestGroup> rg(new RequestGroup(getGID(option), option));
|
|
|
SharedHandle<DownloadContext> dctx
|
|
|
(new DownloadContext(METADATA_PIECE_SIZE, 0,
|
|
|
A2STR::NIL));
|
|
@@ -432,10 +454,18 @@ void createRequestGroupForUri
|
|
|
size_t numSplit = option->getAsInt(PREF_SPLIT);
|
|
|
std::vector<std::string> streamURIs;
|
|
|
splitURI(streamURIs, nargs.begin(), strmProtoEnd, numSplit, numIter);
|
|
|
- SharedHandle<RequestGroup> rg =
|
|
|
- createRequestGroup(option, streamURIs, true);
|
|
|
- rg->setNumConcurrentCommand(numSplit);
|
|
|
- result.push_back(rg);
|
|
|
+ try {
|
|
|
+ SharedHandle<RequestGroup> rg =
|
|
|
+ createRequestGroup(option, streamURIs, true);
|
|
|
+ rg->setNumConcurrentCommand(numSplit);
|
|
|
+ result.push_back(rg);
|
|
|
+ } catch(RecoverableException& e) {
|
|
|
+ if(throwOnError) {
|
|
|
+ throw;
|
|
|
+ } else {
|
|
|
+ A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
// process remaining URIs(local metalink, BitTorrent files)
|
|
|
std::for_each(strmProtoEnd, nargs.end(),
|
|
@@ -522,6 +552,7 @@ createMetadataInfoFromFirstFileEntry(const SharedHandle<DownloadContext>& dctx)
|
|
|
void removeOneshotOption(const SharedHandle<Option>& option)
|
|
|
{
|
|
|
option->remove(PREF_PAUSE);
|
|
|
+ option->remove(PREF_GID);
|
|
|
}
|
|
|
|
|
|
} // namespace aria2
|