From 2097b5e29ae1009bc4030bd6fe295f614ac9f921 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 12 Feb 2010 13:53:52 +0000 Subject: [PATCH] 2010-02-12 Tatsuhiro Tsujikawa Fixed the bug that aria2 doesn't handle return value if error occurred before download begins. * src/MultiUrlRequestInfo.cc * src/main.cc --- ChangeLog | 7 ++ src/MultiUrlRequestInfo.cc | 3 + src/main.cc | 144 ++++++++++++++++++------------------- 3 files changed, 82 insertions(+), 72 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb68ddff..7f58bfb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-12 Tatsuhiro Tsujikawa + + Fixed the bug that aria2 doesn't handle return value if error + occurred before download begins. + * src/MultiUrlRequestInfo.cc + * src/main.cc + 2010-02-11 Tatsuhiro Tsujikawa Removed SegmentManFactory class. diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc index b9cfab0c..88ec284e 100644 --- a/src/MultiUrlRequestInfo.cc +++ b/src/MultiUrlRequestInfo.cc @@ -190,6 +190,9 @@ downloadresultcode::RESULT MultiUrlRequestInfo::execute() } } } catch(RecoverableException& e) { + if(returnValue == downloadresultcode::FINISHED) { + returnValue = downloadresultcode::UNKNOWN_ERROR; + } _logger->error(EX_EXCEPTION_CAUGHT, e); } #ifdef SIGHUP diff --git a/src/main.cc b/src/main.cc index 92239efc..b5d6ecee 100644 --- a/src/main.cc +++ b/src/main.cc @@ -195,105 +195,105 @@ downloadresultcode::RESULT main(int argc, char* argv[]) SocketCore::useSelect(); } downloadresultcode::RESULT exitStatus = downloadresultcode::FINISHED; - try { - Logger* logger = LogFactory::getInstance(); - logger->info("<<--- --- --- ---"); - logger->info(" --- --- --- ---"); - logger->info(" --- --- --- --->>"); - logger->info("%s %s %s", PACKAGE, PACKAGE_VERSION, TARGET); - logger->info(MSG_LOGGING_STARTED); + + Logger* logger = LogFactory::getInstance(); + logger->info("<<--- --- --- ---"); + logger->info(" --- --- --- ---"); + logger->info(" --- --- --- --->>"); + logger->info("%s %s %s", PACKAGE, PACKAGE_VERSION, TARGET); + logger->info(MSG_LOGGING_STARTED); #ifdef ENABLE_MESSAGE_DIGEST - MessageDigestHelper::staticSHA1DigestInit(); + MessageDigestHelper::staticSHA1DigestInit(); #endif // ENABLE_MESSAGE_DIGEST - if(op->getAsBool(PREF_DISABLE_IPV6)) { - SocketCore::setProtocolFamily(AF_INET); - // Get rid of AI_ADDRCONFIG. It causes name resolution error - // when none of network interface has IPv4 address. - setDefaultAIFlags(0); - } - // Bind interface - if(!op->get(PREF_INTERFACE).empty()) { - std::string iface = op->get(PREF_INTERFACE); - SocketCore::bindAddress(iface); - } + if(op->getAsBool(PREF_DISABLE_IPV6)) { + SocketCore::setProtocolFamily(AF_INET); + // Get rid of AI_ADDRCONFIG. It causes name resolution error + // when none of network interface has IPv4 address. + setDefaultAIFlags(0); + } + // Bind interface + if(!op->get(PREF_INTERFACE).empty()) { + std::string iface = op->get(PREF_INTERFACE); + SocketCore::bindAddress(iface); + } #ifdef SIGPIPE - util::setGlobalSignalHandler(SIGPIPE, SIG_IGN, 0); + util::setGlobalSignalHandler(SIGPIPE, SIG_IGN, 0); #endif #ifdef SIGCHLD - // Avoid to create zombie process when forked child processes are - // died. - util::setGlobalSignalHandler(SIGCHLD, SIG_IGN, 0); + // Avoid to create zombie process when forked child processes are + // died. + util::setGlobalSignalHandler(SIGCHLD, SIG_IGN, 0); #endif // SIGCHILD - std::deque > requestGroups; + std::deque > requestGroups; #ifdef ENABLE_BITTORRENT - if(!op->blank(PREF_TORRENT_FILE)) { + if(!op->blank(PREF_TORRENT_FILE)) { + if(op->get(PREF_SHOW_FILES) == V_TRUE) { + showTorrentFile(op->get(PREF_TORRENT_FILE)); + return exitStatus; + } else { + createRequestGroupForBitTorrent(requestGroups, op, args); + } + } + else +#endif // ENABLE_BITTORRENT +#ifdef ENABLE_METALINK + if(!op->blank(PREF_METALINK_FILE)) { if(op->get(PREF_SHOW_FILES) == V_TRUE) { - showTorrentFile(op->get(PREF_TORRENT_FILE)); + showMetalinkFile(op->get(PREF_METALINK_FILE), op); return exitStatus; } else { - createRequestGroupForBitTorrent(requestGroups, op, args); + createRequestGroupForMetalink(requestGroups, op); } } else -#endif // ENABLE_BITTORRENT -#ifdef ENABLE_METALINK - if(!op->blank(PREF_METALINK_FILE)) { - if(op->get(PREF_SHOW_FILES) == V_TRUE) { - showMetalinkFile(op->get(PREF_METALINK_FILE), op); - return exitStatus; - } else { - createRequestGroupForMetalink(requestGroups, op); - } - } - else #endif // ENABLE_METALINK - if(!op->blank(PREF_INPUT_FILE)) { - createRequestGroupForUriList(requestGroups, op); + if(!op->blank(PREF_INPUT_FILE)) { + createRequestGroupForUriList(requestGroups, op); #if defined ENABLE_BITTORRENT || defined ENABLE_METALINK - } else if(op->get(PREF_SHOW_FILES) == V_TRUE) { - showFiles(args, op); - return exitStatus; + } else if(op->get(PREF_SHOW_FILES) == V_TRUE) { + showFiles(args, op); + return exitStatus; #endif // ENABLE_METALINK || ENABLE_METALINK - } else { - createRequestGroupForUri(requestGroups, op, args); - } + } else { + createRequestGroupForUri(requestGroups, op, args); + } - // Remove option values which is only valid for URIs specified in - // command-line. If they are left, because op is used as a - // template for new RequestGroup(such as created in XML-RPC - // command), they causes unintentional effect. - op->remove(PREF_OUT); - op->remove(PREF_FORCE_SEQUENTIAL); - op->remove(PREF_INPUT_FILE); - op->remove(PREF_INDEX_OUT); - op->remove(PREF_SELECT_FILE); - if( + // Remove option values which is only valid for URIs specified in + // command-line. If they are left, because op is used as a + // template for new RequestGroup(such as created in XML-RPC + // command), they causes unintentional effect. + op->remove(PREF_OUT); + op->remove(PREF_FORCE_SEQUENTIAL); + op->remove(PREF_INPUT_FILE); + op->remove(PREF_INDEX_OUT); + op->remove(PREF_SELECT_FILE); + if( #ifdef ENABLE_XML_RPC - !op->getAsBool(PREF_ENABLE_XML_RPC) && + !op->getAsBool(PREF_ENABLE_XML_RPC) && #endif // ENABLE_XML_RPC - requestGroups.empty()) { - std::cout << MSG_NO_FILES_TO_DOWNLOAD << std::endl; - } else { - exitStatus = MultiUrlRequestInfo(requestGroups, op, getStatCalc(op), - getSummaryOut(op)).execute(); - } - } catch(Exception& ex) { - std::cerr << EX_EXCEPTION_CAUGHT << "\n" << ex.stackTrace() << std::endl; - exitStatus = downloadresultcode::UNKNOWN_ERROR; + requestGroups.empty()) { + std::cout << MSG_NO_FILES_TO_DOWNLOAD << std::endl; + } else { + exitStatus = MultiUrlRequestInfo(requestGroups, op, getStatCalc(op), + getSummaryOut(op)).execute(); } - LogFactory::release(); return exitStatus; } } // namespace aria2 -int main(int argc, char* argv[]) { - aria2::Platform platform; - - aria2::downloadresultcode::RESULT r = aria2::main(argc, argv); - +int main(int argc, char* argv[]) +{ + aria2::downloadresultcode::RESULT r; + try { + aria2::Platform platform; + r = aria2::main(argc, argv); + } catch(aria2::Exception& ex) { + std::cerr << EX_EXCEPTION_CAUGHT << "\n" << ex.stackTrace() << std::endl; + r = aria2::downloadresultcode::UNKNOWN_ERROR; + } return r; }