mirror of https://github.com/aria2/aria2
Pass first filename as 2nd argument to command specified by
--on-download-* option.pull/1/head
parent
c03ab007a3
commit
567b424907
|
@ -261,22 +261,23 @@ bool RequestGroupMan::removeReservedGroup(gid_t gid)
|
|||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void executeStopHook
|
||||
(const SharedHandle<DownloadResult>& result, const Option* option)
|
||||
(const SharedHandle<RequestGroup>& group,
|
||||
const Option* option,
|
||||
error_code::Value result)
|
||||
{
|
||||
if(result->result == error_code::FINISHED &&
|
||||
if(result == error_code::FINISHED &&
|
||||
!option->blank(PREF_ON_DOWNLOAD_COMPLETE)) {
|
||||
util::executeHook(option->get(PREF_ON_DOWNLOAD_COMPLETE),
|
||||
util::itos(result->gid));
|
||||
} else if(result->result != error_code::IN_PROGRESS &&
|
||||
util::executeHookByOptName(group, option, PREF_ON_DOWNLOAD_COMPLETE);
|
||||
} else if(result != error_code::IN_PROGRESS &&
|
||||
!option->blank(PREF_ON_DOWNLOAD_ERROR)) {
|
||||
util::executeHook(option->get(PREF_ON_DOWNLOAD_ERROR),
|
||||
util::itos(result->gid));
|
||||
util::executeHookByOptName(group, option, PREF_ON_DOWNLOAD_ERROR);
|
||||
} else if(!option->blank(PREF_ON_DOWNLOAD_STOP)) {
|
||||
util::executeHook(option->get(PREF_ON_DOWNLOAD_STOP),
|
||||
util::itos(result->gid));
|
||||
util::executeHookByOptName(group, option, PREF_ON_DOWNLOAD_STOP);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
|
@ -368,8 +369,8 @@ public:
|
|||
} else {
|
||||
SharedHandle<DownloadResult> dr = group->createDownloadResult();
|
||||
e_->getRequestGroupMan()->addDownloadResult(dr);
|
||||
executeStopHook(group, e_->getOption(), dr->result);
|
||||
group->releaseRuntimeResource(e_);
|
||||
executeStopHook(dr, e_->getOption());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -313,6 +313,7 @@ createBtMagnetRequestGroup(const std::string& magnetLink,
|
|||
rg->setDiskWriterFactory
|
||||
(SharedHandle<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
|
||||
rg->setMetadataInfo(createMetadataInfo(magnetLink));
|
||||
rg->markInMemoryDownload();
|
||||
return rg;
|
||||
}
|
||||
} // namespace
|
||||
|
|
27
src/util.cc
27
src/util.cc
|
@ -80,6 +80,8 @@
|
|||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "Option.h"
|
||||
#include "DownloadContext.h"
|
||||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigest.h"
|
||||
# include "MessageDigestHelper.h"
|
||||
|
@ -1451,17 +1453,23 @@ void removeMetalinkContentTypes(const SharedHandle<RequestGroup>& group)
|
|||
}
|
||||
}
|
||||
|
||||
void executeHook(const std::string& command, const std::string& arg)
|
||||
namespace {
|
||||
|
||||
void executeHook
|
||||
(const std::string& command,
|
||||
const std::string& gid,
|
||||
const std::string& firstFilename)
|
||||
{
|
||||
A2_LOG_INFO(fmt("Executing user command: %s %s",
|
||||
A2_LOG_INFO(fmt("Executing user command: %s %s %s",
|
||||
command.c_str(),
|
||||
arg.c_str()));
|
||||
gid.c_str(),
|
||||
firstFilename.c_str()));
|
||||
#ifndef __MINGW32__
|
||||
pid_t cpid = fork();
|
||||
if(cpid == -1) {
|
||||
A2_LOG_ERROR("fork() failed. Cannot execute user command.");
|
||||
} else if(cpid == 0) {
|
||||
execl(command.c_str(), command.c_str(), arg.c_str(),
|
||||
execl(command.c_str(), command.c_str(), gid.c_str(), firstFilename.c_str(),
|
||||
reinterpret_cast<char*>(0));
|
||||
perror(("Could not execute user command: "+command).c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1476,7 +1484,7 @@ void executeHook(const std::string& command, const std::string& arg)
|
|||
memset(&pi, 0, sizeof (pi));
|
||||
|
||||
std::string cmdline = command;
|
||||
strappend(cmdline, " ", arg);
|
||||
strappend(cmdline, " ", gid, " \"", firstFilename, "\"");
|
||||
|
||||
DWORD rc = CreateProcess(
|
||||
NULL,
|
||||
|
@ -1496,6 +1504,8 @@ void executeHook(const std::string& command, const std::string& arg)
|
|||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void executeHookByOptName
|
||||
(const SharedHandle<RequestGroup>& group, const Option* option,
|
||||
const std::string& opt)
|
||||
|
@ -1507,7 +1517,12 @@ void executeHookByOptName
|
|||
(const RequestGroup* group, const Option* option, const std::string& opt)
|
||||
{
|
||||
if(!option->blank(opt)) {
|
||||
executeHook(option->get(opt), util::itos(group->getGID()));
|
||||
const SharedHandle<DownloadContext> dctx = group->getDownloadContext();
|
||||
std::string firstFilename;
|
||||
if(!group->inMemoryDownload() && !dctx->getFileEntries().empty()) {
|
||||
firstFilename = group->getFirstFilePath();
|
||||
}
|
||||
executeHook(option->get(opt), util::itos(group->getGID()), firstFilename);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -416,9 +416,6 @@ bool inSameCidrBlock(const std::string& ip1, const std::string& ip2, int bits);
|
|||
|
||||
void removeMetalinkContentTypes(const SharedHandle<RequestGroup>& group);
|
||||
|
||||
// No throw
|
||||
void executeHook(const std::string& command, const std::string& arg);
|
||||
|
||||
// No throw
|
||||
void executeHookByOptName
|
||||
(const SharedHandle<RequestGroup>& group, const Option* option,
|
||||
|
|
Loading…
Reference in New Issue