Added --gid option

This option sets GID manually. aria2 identifies each download by the
ID called GID. The GID must be hex string of 16 characters, thus
[0-9a-zA-Z] are allowed and leading zeros must not be stripped. The
GID all 0 is reserved and must not be used. The GID must be unique,
otherwise error is reported and the download is not added.  This
option is useful when restoring the sessions saved using
--save-session option. If this option is not used, new GID is
generated by aria2.
pull/38/head
Tatsuhiro Tsujikawa 2012-12-16 18:22:13 +09:00
parent b9da9d4ed3
commit 0001f4cfbd
7 changed files with 65 additions and 7 deletions

View File

@ -231,6 +231,7 @@ OptionParser.new do |opt|
opt.on("--save-session FILE"){|val| options["save-session"]=val}
opt.on("--server-stat-of FILE"){|val| options["server-stat-of"]=val}
opt.on("--save-cookies FILE"){|val| options["save-cookies"]=val}
opt.on("--gid GID"){|val| options["gid"]=val}
opt.on("--server SERVER", "hostname of XML-RPC server. Default: localhost"){|val| options["server"]=val }
opt.on("--port PORT", "port of XML-RPC server. Default: 6800"){|val| options["port"]=val }

View File

@ -402,6 +402,15 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_BASIC);
handlers.push_back(op);
}
{
OptionHandler* op(new DefaultOptionHandler
(PREF_GID,
TEXT_GID,
NO_DEFAULT_VALUE));
op->addTag(TAG_ADVANCED);
op->setInitialOption(true);
handlers.push_back(op);
}
#ifdef ENABLE_MESSAGE_DIGEST
{
OptionHandler* op(new BooleanOptionHandler

View File

@ -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

View File

@ -272,6 +272,7 @@ error_code::Value main(int argc, char* argv[])
op->remove(PREF_SELECT_FILE);
op->remove(PREF_PAUSE);
op->remove(PREF_CHECKSUM);
op->remove(PREF_GID);
if(!op->getAsBool(PREF_ENABLE_RPC) && requestGroups.empty() &&
!uriListParser) {
global::cout()->printf("%s\n", MSG_NO_FILES_TO_DOWNLOAD);

View File

@ -352,6 +352,8 @@ const Pref* PREF_ENABLE_MMAP = makePref("enable-mmap");
const Pref* PREF_FORCE_SAVE = makePref("force-save");
// value: 1*digit
const Pref* PREF_DISK_CACHE = makePref("disk-cache");
// value: string
const Pref* PREF_GID = makePref("gid");
/**
* FTP related preferences

View File

@ -287,6 +287,8 @@ extern const Pref* PREF_ENABLE_MMAP;
extern const Pref* PREF_FORCE_SAVE;
// value: 1*digit
extern const Pref* PREF_DISK_CACHE;
// value: string
extern const Pref* PREF_GID;
/**
* FTP related preferences

View File

@ -927,3 +927,15 @@
" cached in memory, we don't need to read them\n" \
" from the disk.\n" \
" SIZE can include K or M(1K = 1024, 1M = 1024K).")
#define TEXT_GID \
_(" --gid=GID Set GID manually. aria2 identifies each\n" \
" download by the ID called GID. The GID must be\n" \
" hex string of 16 characters, thus [0-9a-zA-Z]\n" \
" are allowed and leading zeros must not be\n" \
" stripped. The GID all 0 is reserved and must\n" \
" not be used. The GID must be unique, otherwise\n" \
" error is reported and the download is not added.\n" \
" This option is useful when restoring the\n" \
" sessions saved using --save-session option. If\n" \
" this option is not used, new GID is generated\n" \
" by aria2.")