/* */ #include "CheckIntegrityCommand.h" #include "CheckIntegrityEntry.h" #include "DownloadEngine.h" #include "RequestGroup.h" #include "Logger.h" #include "message.h" #include "prefs.h" #include "DownloadContext.h" #include "a2functional.h" #include "RecoverableException.h" #include "util.h" #include "RequestGroupMan.h" #include "FileAllocationEntry.h" #include "ServerStatMan.h" namespace aria2 { CheckIntegrityCommand::CheckIntegrityCommand (cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e, const SharedHandle& entry): RealtimeCommand(cuid, requestGroup, e), _entry(entry) {} CheckIntegrityCommand::~CheckIntegrityCommand() {} bool CheckIntegrityCommand::executeInternal() { if(getRequestGroup()->isHaltRequested()) { getDownloadEngine()->getCheckIntegrityMan()->dropPickedEntry(); return true; } _entry->validateChunk(); if(_entry->finished()) { getDownloadEngine()->getCheckIntegrityMan()->dropPickedEntry(); // Enable control file saving here. See also // RequestGroup::processCheckIntegrityEntry() to know why this is // needed. getRequestGroup()->enableSaveControlFile(); if(getRequestGroup()->downloadFinished()) { getLogger()->notice (MSG_VERIFICATION_SUCCESSFUL, getRequestGroup()->getDownloadContext()->getBasePath().c_str()); std::vector commands; try { _entry->onDownloadFinished(commands, getDownloadEngine()); } catch(RecoverableException& e) { std::for_each(commands.begin(), commands.end(), Deleter()); throw; } getDownloadEngine()->addCommand(commands); } else { getLogger()->error (MSG_VERIFICATION_FAILED, getRequestGroup()->getDownloadContext()->getBasePath().c_str()); std::vector commands; try { _entry->onDownloadIncomplete(commands, getDownloadEngine()); } catch(RecoverableException& e) { std::for_each(commands.begin(), commands.end(), Deleter()); throw; } getDownloadEngine()->addCommand(commands); } getDownloadEngine()->setNoWait(true); return true; } else { getDownloadEngine()->addCommand(this); return false; } } bool CheckIntegrityCommand::handleException(Exception& e) { getDownloadEngine()->getCheckIntegrityMan()->dropPickedEntry(); getLogger()->error(MSG_FILE_VALIDATION_FAILURE, e, util::itos(getCuid()).c_str()); getLogger()->error (MSG_DOWNLOAD_NOT_COMPLETE, util::itos(getCuid()).c_str(), getRequestGroup()->getDownloadContext()->getBasePath().c_str()); return true; } } // namespace aria2