|
@@ -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);
|
|
|
}
|
|
|
}
|
|
|
|